Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Boost/CentOS连接问题_Boost_Linker_Centos - Fatal编程技术网

Boost/CentOS连接问题

Boost/CentOS连接问题,boost,linker,centos,Boost,Linker,Centos,我正在努力学习Boost线程。 我正在使用在线教程中的代码,在出现一些错误后,我意识到我需要更新版本的Boost,因此我将最新版本的Boost下载到一个目录中,解压缩并使用以下命令安装: ./bootstrap.sh ./bjam install 我尝试运行的示例代码如下: #include <boost/thread.hpp> #include <iostream> using namespace std; using namespace boost; voi

我正在努力学习Boost线程。 我正在使用在线教程中的代码,在出现一些错误后,我意识到我需要更新版本的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不同),但当我运行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
export LD_LIBRARY_PATH="/usr/local/lib/"
所以我不明白为什么它不起作用。 我认为这与编译行的-lboost_线程部分有关。 我尝试通过以下方式直接链接到库:

g++ -Wall -L/usr/local/lib libboost_thread.a threadtest.cpp -o threadtest
但它还是找不到文件。
有人能帮我吗?

我需要用以下命令将我的lib目录的路径重新添加到我的LD\u LIBRARY\u路径:

-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
export LD_LIBRARY_PATH="/usr/local/lib/"
这就成功了