Cern ROOT XCode IDE 不编译

Cern ROOT XCode IDE does not compile

我关注了同一项目中的 Setup Guide of another Post and got a working example using XCode as ROOT IDE. Now I tried to include the 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 内编译它会产生以下错误:

Undefined symbols for architecture x86_64: defined symbols for architecture x86_64: "ROOT::Minuit2::Minuit2Minimizer::SetFunction(ROOT::Math::IBaseFunctionMultiDim const&)", referenced from: _main in main.o

还有一些未定义的符号。

我做错了什么?


我通过

使用 Macports 安装了 ROOT
sudo port install root6

并确保安装了变体 +minuit2。然后我添加了 Search PathsLinking:

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

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

-lMinuit2 

到构建设置中的其他标志。 不知何故

root-config --libs

不会自动添加 minuit2 链接器。