构建可执行文件时未找到 pthread 库?

发布于 2024-10-12 01:55:04 字数 1964 浏览 2 评论 0原文

我正在尝试为我创建的 ThreadManager 类构建一个简单的测试程序。正如您在下面的输出中看到的,我的 ThreadManager 和主代码似乎可以很好地编译成对象文件,但是在创建可执行文件时,它似乎无法找到对 pthread 类中任何函数的正确引用。我缺少什么?

g++    -c -o ThreadManager.o ThreadManager.cpp  
g++    -c -o main.o main.cpp  
g++ -o tm_test ThreadManager.o main.o -g    -lm  

ThreadManager.o: In function `ThreadManager::Create(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void* (*)(void*))':  
ThreadManager.cpp:(.text+0x276): undefined reference to `pthread_create'  
ThreadManager.o: In function `ThreadManager::Create(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void* (*)(void*), void*)':  
ThreadManager.cpp:(.text+0x4a3): undefined reference to `pthread_create'  
ThreadManager.o: In function `ThreadManager::Create(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void* (*)(void*), void*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':  
ThreadManager.cpp:(.text+0x70b): undefined reference to `pthread_create'  
ThreadManager.o: In function `ThreadManager::Cleanup(int)':  
ThreadManager.cpp:(.text+0x8d4): undefined reference to `pthread_join'  
ThreadManager.cpp:(.text+0xa5f): undefined reference to `pthread_join'  
ThreadManager.cpp:(.text+0xbe1): undefined reference to `pthread_kill'  
ThreadManager.o: In function `ThreadManager::Resurrect()':  
ThreadManager.cpp:(.text+0xe8c): undefined reference to `pthread_create'  
ThreadManager.o: In function `ThreadManager::Kill(int)':  
ThreadManager.cpp:(.text+0x125f): undefined reference to `pthread_cancel'  
ThreadManager.cpp:(.text+0x1285): undefined reference to `pthread_join'  
ThreadManager.o:(.rodata+0x1a0): undefined reference to `pthread_cancel'  
main.o:(.rodata+0x5c): undefined reference to `pthread_cancel'  
collect2: ld returned 1 exit status  
make: *** [tm_test] Error 1

谢谢,

I'm trying to build a simple test program for a ThreadManager class I created. As you can see in the output below, my ThreadManager and main code seems to compile into object files just fine, but then when creating the executable, it can't seem to find proper references to any of the functions from the pthread class. What am I missing?

g++    -c -o ThreadManager.o ThreadManager.cpp  
g++    -c -o main.o main.cpp  
g++ -o tm_test ThreadManager.o main.o -g    -lm  

ThreadManager.o: In function `ThreadManager::Create(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void* (*)(void*))':  
ThreadManager.cpp:(.text+0x276): undefined reference to `pthread_create'  
ThreadManager.o: In function `ThreadManager::Create(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void* (*)(void*), void*)':  
ThreadManager.cpp:(.text+0x4a3): undefined reference to `pthread_create'  
ThreadManager.o: In function `ThreadManager::Create(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, void* (*)(void*), void*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':  
ThreadManager.cpp:(.text+0x70b): undefined reference to `pthread_create'  
ThreadManager.o: In function `ThreadManager::Cleanup(int)':  
ThreadManager.cpp:(.text+0x8d4): undefined reference to `pthread_join'  
ThreadManager.cpp:(.text+0xa5f): undefined reference to `pthread_join'  
ThreadManager.cpp:(.text+0xbe1): undefined reference to `pthread_kill'  
ThreadManager.o: In function `ThreadManager::Resurrect()':  
ThreadManager.cpp:(.text+0xe8c): undefined reference to `pthread_create'  
ThreadManager.o: In function `ThreadManager::Kill(int)':  
ThreadManager.cpp:(.text+0x125f): undefined reference to `pthread_cancel'  
ThreadManager.cpp:(.text+0x1285): undefined reference to `pthread_join'  
ThreadManager.o:(.rodata+0x1a0): undefined reference to `pthread_cancel'  
main.o:(.rodata+0x5c): undefined reference to `pthread_cancel'  
collect2: ld returned 1 exit status  
make: *** [tm_test] Error 1

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜宝宝 2024-10-19 01:55:04

链接到pthread库;

g++ -c -o ThreadManager.o ThreadManager.cpp 
g++ -c -o main.o main.cpp 
g++ -o tm_test -lm -lpthread

Link to the pthread library;

g++ -c -o ThreadManager.o ThreadManager.cpp 
g++ -c -o main.o main.cpp 
g++ -o tm_test -lm -lpthread
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文