在XCode中从Cern设置ROOT,正确链接库管理器 [英] Setting up ROOT from Cern in XCode, linking the librariers correctly

查看:655
本文介绍了在XCode中从Cern设置ROOT,正确链接库管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的XCode IDE中从CERN设置ROOT,但我在链接库时遇到问题。我使用root 6.04.14和xcode 7.3。
我创建了一个模拟项目,其中我只有一个.cpp,其中包括一个基本类从根(#includeTFile.h)。我可以从命令行编译:

I want to set up ROOT from CERN in my XCode IDE but I'm having problems linking the libraries. I'm using root 6.04.14 and xcode 7.3. I created a mock up project where I simply have a .cpp where I include a basic class from root (#include "TFile.h"). This I can compile from command line by:

clang ++ -std = c ++ 11 -I / opt / root / root-6.04.14 / include / root -L /opt/root/root-6.04.14/lib/root -lCore main.cpp

clang++ -std=c++11 -I/opt/root/root-6.04.14/include/root -L/opt/root/root-6.04.14/lib/root -lCore main.cpp

现在介绍如何设置XCode IDE中的所有内容。我在头搜索路径中包含/opt/root/root-6.04.14/include/root,XCode不是抱怨,所以我想它找到头文件。我尝试添加/opt/root/root-6.04.14/lib/root -lCore到库搜索路径,但我得到错误:
在包含从/Applications/Xcode.app/Contents/Developer/的文件Toolchains / XcodeDefault.xctoolchain / usr / bin /../ include / c ++ / v1 / cmath:301:
/opt/root/root-6.04.14/include/root/Math/math.h:65: 11:错误:在全局命名空间中没有名为log1p的成员;你的意思是简单的log1p吗?
return :: log1p(x);
^〜
/opt/root/root-6.04.14/include/root/Math/math.h:63:15:注意:'log1p'在这里声明
inline double log1p double x){
^
/opt/root/root-6.04.14/include/root/Math/math.h:76:11:error:在全局命名空间中没有名为expm1的成员;你的意思是简单的expm1吗?
return :: expm1(x);
^〜
/opt/root/root-6.04.14/include/root/Math/math.h:74:15:note:'expm1'这里声明
inline double expm1 double x){

Now it comes to setting up everything in the XCode IDE. I included "/opt/root/root-6.04.14/include/root" in the header search path and XCode is not complaining, so I guess it finds the header files. I tried adding "/opt/root/root-6.04.14/lib/root -lCore" to the library search path but I get errors: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:301: /opt/root/root-6.04.14/include/root/Math/math.h:65:11: error: no member named 'log1p' in the global namespace; did you mean simply 'log1p'? return ::log1p(x); ^~ /opt/root/root-6.04.14/include/root/Math/math.h:63:15: note: 'log1p' declared here inline double log1p( double x) { ^ /opt/root/root-6.04.14/include/root/Math/math.h:76:11: error: no member named 'expm1' in the global namespace; did you mean simply 'expm1'? return ::expm1(x); ^~ /opt/root/root-6.04.14/include/root/Math/math.h:74:15: note: 'expm1' declared here inline double expm1( double x) {

等等...
此外,当我看到终端命令XCode正在运行(至少这是我认为它)没有包括-L / opt / root / root-6.04.14 / lib / root -lCore。然后我试图把-L / opt / root / root-6.04.14 / lib / root -lCore放入其他链接器标志。现在它包括在终端命令,但仍然给我相同的错误。

and so on... Furthermore when I look at the terminal command XCode is running(at least that is what I think it does) there is no "-L/opt/root/root-6.04.14/lib/root -lCore" included. I then tried to put "-L/opt/root/root-6.04.14/lib/root -lCore" into other linker flags. Now it is included in the terminal command but still giving me the same error.

问题1:
我注意到XCode正在运行/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang而我一直在使用clang ++,哪里是差别,如何可以改变呢?
Question2:
将目录添加到库搜索路径并通过链接器标志放入它们之间有什么区别?

Question1: I noticed XCode is running "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" while I have been using clang++, where is the difference and how can I change it? Question2: What is the difference between adding the directory to the library search path and putting it in via the linker flag? Question3: The big one, where do I mess up?

任何帮助将非常感激!

干杯

推荐答案

你可能已经知道了,但是为了防止有人绊倒这个问题在这里是我如何在xcode中设置我的ROOT(v6.06.04)。

You've probably already figured this out, but just in case someone else stumbles on this issue here's how I've setup my ROOT (v6.06.04) in xcode. To demonstrate, lets start from scratch with a fresh xcode project.

假设我们要在xcode中运行下面的程序(注意它使用了ROOT类)。

Say we want to run the following program in xcode (note that it uses ROOT classes)

#include <iostream>
#include "TApplication.h"
#include "TCanvas.h"
#include "TGraph.h"
#include <vector>

int main(int argc, const char * argv[]) {
    // Create a TApplication so that we can get plot the histogram
    TApplication* myApp = new TApplication("myApp", 0, 0) ;

    // Create some vector information
    std::vector<double> x(100), y(100) ;

    for (int i=0; i<x.size(); i++) {
        x[i] = i * (10.0/x.size()) ;
        y[i] = std::cos(x[i]) ;
    }

    // Create a TGraph
    TGraph* graph = new TGraph(x.size(), &x[0], &y[0]) ;

    // Create a canvas and draw the graph
    TCanvas* canvas = new TCanvas("canvas","canvas") ;
    graph->Draw("ap0") ;
    canvas->Update() ;

    // Run the TApplication to produce all of the plots
    myApp->Run() ;
    return 0;
}

如果你只是复制并粘贴到xcode的程序, ROOT头不能被xcode识别,你得到错误'XXX.h'文件未找到。这显然是因为我们需要告诉xcode在哪里找到头。

If you just copy and paste this program into xcode you'll see that the ROOT headers arent recognized by xcode and you get the error 'XXX.h' file not found. This is obviously because we need to tell xcode where to find the headers.


  1. 点击左侧菜单中的项目

  2. + - >添加用户定义的设置。


  1. 这将在用户定义部分下添加一个参数。调用新参数ROOTSYS,并将其指向ROOT安装的顶层目录。对我来说,这是 /Users/user/root_cern/root_v6.06.04 / 。 (注意:这一步不是绝对必要的,但是使其余的不那么痛苦,并允许您更新ROOT安装,而不必更改下面的标题和库路径)

  1. This will add a parameter under the "User-Defined" section. Call the new parameter "ROOTSYS" and point it to the top directory of your ROOT installation. For me this is /Users/user/root_cern/root_v6.06.04/. (Note: This step isnt absolutely necessary but makes the rest less painful and allows you to update your ROOT installation without having to change the header and library paths below)

现在(仍然在构建设置)转到搜索路径 - >用户标题搜索路径。在此字段中添加路径$(ROOTSYS)/ include

Now (still in "Build Settings") go to "Search Paths" -> "User Header Search Paths". In this field add the path "$(ROOTSYS)/include"

此时,我们的标头上的错误已经消失了!不幸的是,程序不会构建。看看构建错误显示有TONS的链接错误!显然,我们需要更新我们的链接器标志,以包含我们要编译的所有ROOT库。

At this point the nasty errors on our headers have gone away! Unfortunately, the program wont build. A look at the build errors shows that there are TONS of linking errors! Clearly we need to update our linker flags to include all the ROOT libraries we want to compile against.


  1. 打开终端并运行 $ ROOTSYS / bin / root-config --libs 。对我来说,输出是:

  1. Open a terminal and run $ROOTSYS/bin/root-config --libs. For me the output is:

-L / Users / user / root_cern / root_v6.06.04 / lib -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad - lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -Wl,-rpath,/ Users / user / root_cern / root_v6.06.04 / lib -stdlib = libc ++ -lm -ldl

-L/Users/user/root_cern/root_v6.06.04/lib -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -Wl,-rpath,/Users/user/root_cern/root_v6.06.04/lib -stdlib=libc++ -lm -ldl

复制上面 root-config 的输出并粘贴到Build Settings - >Linking - >Other链接器标志。请注意,您可以用 $(ROOTSYS)替换路径的所有实例到您的ROOT安装目录,并且您将来在更新ROOT版本时不必更新它们。

Copy the output from the above root-config and paste it under "Build Settings" -> "Linking" -> "Other Linker Flags". Note that you can replace all instances of the path to your ROOT install directory with $(ROOTSYS) and you wont have to update them in the future when you update your ROOT version.

现在程序应该就可以了!如果您仍然遇到链接错误,请确保您尝试构建的 TARGET 继承自项目的链接信息。通过转到您正在构建的目标的其他链接器标记并将其设置为 $(继承)来执行此操作。你会得到一个cos(x)函数的便利图。

Now the program should build just fine! If you're STILL getting the linking errors, make sure that the TARGET you're trying to build inherits it's linking information from the project. Do this by going to "Other Linker Flags" for the target you are building and set it to $(inherited). You'll get the handy plot of a cos(x) function.

几个备注:


  • 如果您不使用TApplication,程序将在您获得机会之前结束看看你的情节。

  • 您可以通过xcode GUI或在绘图的菜单栏中选择文件 - >退出根来结束程序。

  • 如果你想写一个你想要ROOT能够流出到文件的类,情况会更复杂一些。可以通过向目标中添加一个额外的运行脚本构建阶段来实现。现在,这应该让你开始。

这篇关于在XCode中从Cern设置ROOT,正确链接库管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆