C++ C++;加载共享库“未定义符号:pthread_create”时发生Linux错误`

C++ C++;加载共享库“未定义符号:pthread_create”时发生Linux错误`,c++,linux,c++11,pthreads,shared-libraries,C++,Linux,C++11,Pthreads,Shared Libraries,我已经创建了一个编译良好的库。 库文件为“libTextSearch.so” 在库内部,它创建一个线程。我正在为此使用C++11线程: TextSearch::TextSearch(){ std::thread t(&TextSearch::ThreadProc, this); t.detach(); } 正如我所说,这个库是编译的,我有libTextSearch.so文件 我正在尝试在其他应用程序中加载库: void* handle = dlopen("libText

我已经创建了一个编译良好的库。 库文件为“libTextSearch.so”

在库内部,它创建一个
线程
。我正在为此使用C++11线程:

TextSearch::TextSearch(){
    std::thread t(&TextSearch::ThreadProc, this);
    t.detach();
}
正如我所说,这个库是编译的,我有
libTextSearch.so
文件

我正在尝试在其他应用程序中加载库:

void* handle = dlopen("libTextSearch.so", RTLD_LAZY);
if(!handle){
    //std::cout << "\n  Failed to load libTextSearch.so\n\n";
    fprintf(stderr, "dlopen failed: %s\n", dlerror());
    return 1;
}
我已经查过了。我认为这是相关的,但我不知道如何将其应用于我的情况


有什么想法吗?

我不能完全确定,因为我不知道您是如何构建这个项目的,或者libTextSearch.so是如何构建的,但在生成libTextSearch时,您需要以某种方式链接libpthread。通常在构建环境中,您会提供-lpthread作为参数来动态链接到它

gcc -c testsearch.cpp -lpthread -o textsearch.o 

例如,

我不能确切地确定,因为我不知道您是如何构建这个项目的,或者libTextSearch.so是如何构建的,但是在生成libTextSearch时,您需要以某种方式链接libpthread。通常在构建环境中,您会提供-lpthread作为参数来动态链接到它

gcc -c testsearch.cpp -lpthread -o textsearch.o 

例如

只需使用
RTLD\u GLOBAL

void* handlePthread = dlopen("libpthread.so.0", RTLD_GLOBAL | RTLD_LAZY);
if(!handlePthread ){
    //std::cout << "\n  Failed to load libpthread.so.0\n\n";
    fprintf(stderr, "dlopen failed: %s\n", dlerror());
    return 1;
}
void*handlePthread=dlopen(“libpthread.so.0”,RTLD_GLOBAL | RTLD_LAZY);
if(!handleThread){

//std::cout只需
dlopen
thread
库预先与
RTLD\u GLOBAL

void* handlePthread = dlopen("libpthread.so.0", RTLD_GLOBAL | RTLD_LAZY);
if(!handlePthread ){
    //std::cout << "\n  Failed to load libpthread.so.0\n\n";
    fprintf(stderr, "dlopen failed: %s\n", dlerror());
    return 1;
}
void*handlePthread=dlopen(“libpthread.so.0”,RTLD_GLOBAL | RTLD_LAZY);
if(!handleThread){

//std::cout感谢这解决了加载问题,但是,我在
std::thread t(&TextSearch::ThreadProc,this)中面临另一个问题;
。它会导致运行时错误,因为它不喜欢不被视为
pthread
。有什么线索吗?谢谢你的回答,Rama的回答修复了所有问题me@EveryoneHappy coding friends感谢这解决了加载问题,但是,我在
std::thread t(&TextSearch::ThreadProc,this)中面临另一个问题;
。它会导致运行时错误,因为它不喜欢不被视为
pthread
。有什么线索吗?谢谢你的回答,Rama的回答修复了所有问题me@Everyone快乐的编码朋友这就是我所拥有的:
dlopen失败:libpthread.so.0:dlopen()的模式无效:无效参数
@所有人编辑,请用
| RTLD_LAZY
测试打开它,谢谢!修复了我所有的问题这就是我的问题:
dlopen失败:libpthread.so.0:dlopen()模式无效:无效参数
@所有人编辑,请用
| RTLD_LAZY
测试打开它,谢谢!修复了我所有的问题