构建可执行文件时未找到 pthread 库?
我正在尝试为我创建的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接到
pthread
库;Link to the
pthread
library;