简体   繁体   English

将库添加到Eclipse C ++项目(ROOT)

[英]add library to eclipse C++ project (ROOT)

I am trying to import library in eclipse but I cant do it. 我正在尝试在Eclipse中导入库,但我做不到。 I know there many threads already talked about this issue but I couldn't solve my problem with those. 我知道已经有很多线程讨论过这个问题,但是我无法用这些解决问题。 So I appreciate if you can help. 因此,感谢您能提供帮助。 I have text code: 我有文本代码:

#include <iostream>
#include <TRandom1.h>
int main(void) {
  TRandom1* myrand = new TRandom1();
  for(int i=0;i<10;++i) {
    std::cout << myrand->Gaus(5,1) << std::endl;
  }
  return 0;
}

and I build and run it like: 然后像这样构建和运行它:

g++ -c `root-config --cflags` test.cpp
g++ -o randoms `root-config --libs` test.o
./randoms

which works fine. 效果很好。 The result if root-config --cflags is : 如果root-config --cflags的结果是:

-pthread -m64 -I/usr/local/include/root

and result of root-config --libs root-config --libs

-L/usr/local/lib/root -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic

Now when in ecplise I change the C/C++ Build-> C++ compiler -> miscellanoeus to: 现在在ecplise中,我将C/C++ Build-> C++ compiler -> miscellanoeus更改为:

-c `root-config --cflags` -fmessage-length=0

and add root-config --libs to linker miscellanoeus. 并将root-config --libs添加到链接器miscellanoeus。 Now I can build the code . 现在,我可以构建代码了。 but when I am trying to run it I am getting: 但是当我尝试运行它时,我得到:

/home/jd/C-workespace/CERN/Debug/CERN: error while loading shared libraries: libCore.so: cannot open shared object file: No such file or directory

What I am missing here? 我在这里想念的是什么?

您需要在“运行/调试”配置中设置LD_LIBRARY_PATH变量值。

This is a usual compilation error message telling you that it can't find ROOT libraries. 这是一条通常的编译错误消息,告诉您找不到根目录库。 Usually, ROOT comes with a setup.sh script in the ${ROOTSYS}/bin/ directory, which you need to source: it does the environment setup for you, and perhaps simply sourcing it will solve your problem. 通常,ROOT带有$ {ROOTSYS} / bin /目录中的setup.sh脚本,您需要从该脚本中获取该脚本:它会为您执行环境设置,也许只需采购即可解决您的问题。

I'm not familiar with Eclipse, but I think there must be a way in it to specify environment variables, eg $ROOTSYS. 我不熟悉Eclipse,但是我认为必须有一种方法可以指定环境变量,例如$ ROOTSYS。

After 1 minute of googling, I found a promising link: 经过1分钟的谷歌搜索,我发现了一个有希望的链接:

Eclipse Environment variable setup Eclipse环境变量设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM