0
我跟着Setup Guide of another Post,得到了一個使用XCode作爲ROOT IDE的工作示例。現在,我想包括在同一個項目中Minuit2 example code:Cern ROOT XCode IDE無法編譯
#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編譯它產生以下錯誤:
在main.o中 _main:從引用 「ROOT :: Minuit2 :: Minuit2Minimizer :: SetFunction(ROOT ::數學:: IBaseFunctionMultiDim常量&)」,:用於建築x86_64的未定義符號: 爲架構x86_64的定義的符號
和更多未定義的符號。
我做錯了什麼?
我通過
sudo port install root6
與MacPorts的安裝ROOT並確保該變種+ 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
'root-config --libs'不會添加所有的根庫。它只是一小部分核心庫。通常,當你遇到鏈接器錯誤時,你可以檢查'root-config --libdir'中的'* .rootmap'文件,該庫包含你缺少的類。 – pseyfert