Cern ROOT XCode IDE无法编译

时间:2016-11-24 14:27:10

标签: xcode ide root-framework

我关注Setup Guide of another Post并使用XCode作为ROOT IDE获得了一个工作示例。现在我尝试在同一个项目中包含Minuit2 example code

#include "Minuit2/Minuit2Minimizer.h"
#include "Math/Functor.h"

double RosenBrock(const double *xx )
{
    const double_t x = xx[0];
    const double_t y = xx[1];
    const double_t tmp1 = y-x*x;
    const double_t tmp2 = 1-x;
    return 100*tmp1*tmp1+tmp2*tmp2;
}

int main()
{
    // Choose method upon creation between:
    // kMigrad, kSimplex, kCombined,
    // kScan, kFumili

    ROOT::Minuit2::Minuit2Minimizer min ( ROOT::Minuit2::kMigrad );

    min.SetMaxFunctionCalls(1000000);
    min.SetMaxIterations(100000);
    min.SetTolerance(0.001);

    ROOT::Math::Functor f(&RosenBrock,2);
    double step[2] = {0.01,0.01};
    double variable[2] = { -1.,1.2};

    min.SetFunction(f);

    // Set the free variables to be minimized!
    min.SetVariable(0,"x",variable[0], step[0]);
    min.SetVariable(1,"y",variable[1], step[1]);

    min.Minimize();

    const double *xs = min.X();
    std::cout << "Minimum: f(" << xs[0] << "," << xs[1] << "): "
    << RosenBrock(xs) << std::endl;

    return 0;
}

我测试了代码作为根宏并且工作正常,但尝试在XCode中编译它会产生以下错误:

  

架构x86_64的未定义符号:       为架构x86_64定义的符号:         &#34; ROOT :: Minuit2 :: Minuit2Minimizer :: SetFunction(ROOT :: Math :: IBaseFunctionMultiDim const&amp;)&#34;,引自:         _main in main.o

以及更多未定义的符号。

我做错了什么?

我通过

在Macports上安装了ROOT
sudo port install root6

并确保安装了变体+ minuit2。然后我添加了搜索路径关联

Targets > Build Settings > User Header Search Paths > Debug > /opt/local/libexec/root6/include/root
Targets > Build Settings > Other Linker Flags > Debug > -L/opt/local/libexec/root6/lib/root -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lpthread -Wl,-rpath,/opt/local/libexec/root6/lib/root -stdlib=libc++ -lm -ldl

我来自

root/bin/root-config --libs

1 个答案:

答案 0 :(得分:0)

自己回答这个问题: 你必须添加

-lMinuit2 

到Build设置中的其他Flags。 不知何故

root-config --libs

不会自动添加minuit2链接器。