【问题标题】:Boost/CentOS linking issueBoost/CentOS 链接问题
【发布时间】:2011-11-10 14:29:30
【问题描述】:

我正在尝试学习 Boost 线程。 我正在使用在线教程中的代码,在出现一些错误后,我意识到我需要更新版本的 Boost,因此我将其最新版本下载到目录中,解压缩并使用以下命令安装:

./bootstrap.sh
./bjam install

我试图运行的示例代码是这样的:

#include <boost/thread.hpp> 
#include <iostream> 

using namespace std;
using namespace boost;

void threader()
{ 
  for (int i = 0; i < 5; ++i)
  { 
    sleep(1); 
    cout << boost::this_thread::get_id() << "-" << i << endl;
    //cout << "-" << i << endl;
  } 
} 
int main() 
{ 
  thread t(threader);
  sleep(1);
  thread u(threader);
  t.join(); 
  u.join(); 
}

我使用与旧版本 Boost(1.33 与 Centos 作为标准)相同的行编译:

g++ -Wall -L/usr/local/lib -lboost_thread threadtest.cpp -o threadtest

它编译时没有错误(与旧版本的 Boost 不同),但是当我运行 threadtest 时,我得到:

./threadtest: error while loading shared libraries: libboost_thread.so.1.47.0: cannot open shared object file: No such file or directory

查看 /usr/local/lib 目录我可以看到以下内容:

-rw-r--r-- 1 root root   217270 Nov 10 12:50 libboost_thread.a
lrwxrwxrwx 1 root root       25 Nov 10 12:43 libboost_thread.so -> libboost_thread.so.1.47.0
-rwxr-xr-x 1 root root   138719 Nov 10 12:43 libboost_thread.so.1.47.0

所以我看不出它为什么不起作用。 我认为这与编译行的 -lboost_thread 部分有关。 我尝试使用以下方式直接链接到库:

g++ -Wall -L/usr/local/lib libboost_thread.a threadtest.cpp -o threadtest

但它又找不到文件了。 有人可以帮忙吗?

【问题讨论】:

    标签: boost linker centos


    【解决方案1】:

    我需要使用以下内容将我的 lib 目录的路径重新添加到我的 LD_LIBRARY_PATH:

    export LD_LIBRARY_PATH="/usr/local/lib/"
    

    成功了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 2013-09-23
      • 1970-01-01
      • 2016-09-14
      • 2012-11-26
      • 1970-01-01
      相关资源
      最近更新 更多