簡體   English   中英

將庫添加到Eclipse C ++項目(ROOT)

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

我正在嘗試在Eclipse中導入庫,但我做不到。 我知道已經有很多線程討論過這個問題,但是我無法用這些解決問題。 因此,感謝您能提供幫助。 我有文本代碼:

#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;
}

然后像這樣構建和運行它:

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

效果很好。 如果root-config --cflags的結果是:

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

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

現在在ecplise中,我將C/C++ Build-> C++ compiler -> miscellanoeus更改為:

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

並將root-config --libs添加到鏈接器miscellanoeus。 現在,我可以構建代碼了。 但是當我嘗試運行它時,我得到:

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

我在這里想念的是什么?

您需要在“運行/調試”配置中設置LD_LIBRARY_PATH變量值。

這是一條通常的編譯錯誤消息,告訴您找不到根目錄庫。 通常,ROOT帶有$ {ROOTSYS} / bin /目錄中的setup.sh腳本,您需要從該腳本中獲取該腳本:它會為您執行環境設置,也許只需采購即可解決您的問題。

我不熟悉Eclipse,但是我認為必須有一種方法可以指定環境變量,例如$ ROOTSYS。

經過1分鍾的谷歌搜索,我發現了一個有希望的鏈接:

Eclipse環境變量設置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM