g++链接boost库

示例代码:

#include 
#include 
#include 
#include 

void wait(int seconds) {
    boost::this_thread::sleep(boost::posix_time::seconds(seconds));
}

void thread(){
    for (int i=0; i<5; ++i) {
        wait(1);
        std::cout<< i << std::endl;
    }
}

int main(){
    boost::thread t(thread);

    t.join();
    return 0;
}

链接动态库命令:

g++ main.cpp -o main -lboost_system -lboost_thread

报错:

./main: error while loading shared libraries: libboost_system.so.1.66.0: cannot open shared object file: No such file or directory

链接静态库命令:

g++ main.cpp -o main -lboost_system -static -pthread -lboost_thread

你可能感兴趣的:(c/c++)