链接到boost_thread的问题 [英] Problem linking to boost_thread
本文介绍了链接到boost_thread的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图链接到boost 1.47在xubuntu与gcc4.6和glibc 2.13。到目前为止我无法编译以下简单的程序,main.cpp:
#include< cstdlib>
#include< boost / ref.hpp>
#include< boost / thread.hpp>
int main(){
size_t n_threads = boost :: thread :: hardware_concurrency();
return 0;
}
当我编译时:
$ b b
g ++ -lboost_thread -lboost_regex -o mc main.cpp -static -lpthread /usr/local/lib/libboost_regex.a /usr/local/lib/libboost_thread.a
我得到一大堆错误,类似于以下内容:
/usr/local/lib/libboost_thread.a(thread.o):在函数`_ZN5boost9call_onceIPFvvEEEvRNS_9once_flagET_.constprop.100':
pre>
thread.cpp :(。文本+ 0x47):未定义引用`pthread_mutex_lock'
thread.cpp :(。text + 0x73):未定义引用`pthread_cond_wait'
thread.cpp :(。+ 0xb9):未定义引用`pthread_mutex_unlock'
thread.cpp :(。text + 0xc8):未定义引用`pthread_key_create'
thread.cpp :( .text + 0xd2):未定义引用`pthread_mutex_lock'
thread .cpp :( .text + 0xf5):未定义引用`pthread_cond_broadcast'
thread.cpp :(。text + 0x10e):未定义引用`pthread_mutex_unlock'
以及:
/ usr / lib / x86_64- linux-gnu / gcc / x86_64-linux-gnu / 4.6.1 / libgcc_eh.a(unwind-dw2.o):在函数`uw_init_context_1':
(.text + 0x20bd):未定义引用`pthread_once'
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o):在函数`__register_frame_info_bases'中:
(.text + 0x16d4):未定义引用`pthread_mutex_lock'
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2- fde-glibc.o):在函数`__register_frame_info_table_bases'中:
(.text + 0x179b):未定义的引用`pthread_mutex_lock'
/ usr / lib / x86_64-linux-gnu / gcc / x86_64-linux -gnu / 4.6.1 / libgcc_eh.a(unwind-dw2-fde-glibc.o):在函数`__deregister_frame_info_bases'中:
(.text + 0x183e):未定义引用`pthread_mutex_lock'
/ usr / lib / x86_64-linux-gnu / gcc / x86_64-linux-gnu / 4.6.1 / libgcc_eh.a(unwind-dw2-fde-glibc.o):在函数`__deregister_frame_info_bases':
+ 0x18c6):未定义引用`pthread_mutex_unlock'
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o ):在函数`_Unwind_Find_FDE'中:
(.text + 0x1976):未定义引用`pthread_mutex_lock'
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6。 1 / libgcc_eh.a(unwind-dw2-fde-glibc.o):在函数`_Unwind_Find_FDE'中:
(.text + 0x19c7):未定义引用`pthread_mutex_unlock'
/ usr / lib / x86_64 -linux-gnu / gcc / x86_64-linux-gnu / 4.6.1 / libgcc_eh.a(unwind-dw2-fde-glibc.o):在函数`__register_frame_info_bases':
(.text + 0x16f3):undefined引用`pthread_mutex_unlock'
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o):在函数` __register_frame_info_table_bases':
(.text + 0x17ba):未定义引用`pthread_mutex_unlock'
collect2:ld返回1退出状态
这会导致什么问题?
我在这里提供了足够的信息吗?解决方案尝试将-lpthread移动到最后一个参数到链接器。 查看此链接
I'm trying to link with boost 1.47 on xubuntu with gcc4.6 and glibc 2.13. So far I can't compile the following simple program, main.cpp:
#include <cstdlib> #include <boost/ref.hpp> #include <boost/thread.hpp> int main() { size_t n_threads = boost::thread::hardware_concurrency(); return 0; }
when I compile with:
g++ -lboost_thread -lboost_regex -o mc main.cpp -static -lpthread /usr/local/lib/libboost_regex.a /usr/local/lib/libboost_thread.a
I get a bunch of errors from boost similar to the following:
/usr/local/lib/libboost_thread.a(thread.o): In function `_ZN5boost9call_onceIPFvvEEEvRNS_9once_flagET_.constprop.100': thread.cpp:(.text+0x47): undefined reference to `pthread_mutex_lock' thread.cpp:(.text+0x73): undefined reference to `pthread_cond_wait' thread.cpp:(.text+0xb9): undefined reference to `pthread_mutex_unlock' thread.cpp:(.text+0xc8): undefined reference to `pthread_key_create' thread.cpp:(.text+0xd2): undefined reference to `pthread_mutex_lock' thread.cpp:(.text+0xf5): undefined reference to `pthread_cond_broadcast' thread.cpp:(.text+0x10e): undefined reference to `pthread_mutex_unlock'
and also:
/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1': (.text+0x20bd): undefined reference to `pthread_once' /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_bases': (.text+0x16d4): undefined reference to `pthread_mutex_lock' /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_table_bases': (.text+0x179b): undefined reference to `pthread_mutex_lock' /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__deregister_frame_info_bases': (.text+0x183e): undefined reference to `pthread_mutex_lock' /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__deregister_frame_info_bases': (.text+0x18c6): undefined reference to `pthread_mutex_unlock' /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE': (.text+0x1976): undefined reference to `pthread_mutex_lock' /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE': (.text+0x19c7): undefined reference to `pthread_mutex_unlock' /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_bases': (.text+0x16f3): undefined reference to `pthread_mutex_unlock' /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6.1/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_table_bases': (.text+0x17ba): undefined reference to `pthread_mutex_unlock' collect2: ld returned 1 exit status
What would be causing a problem like this? Have I provided enough information here? Any advice for fixing this is greatly appreciated!
解决方案Try moving the "-lpthread" to be the last argument to the linker. See this link
这篇关于链接到boost_thread的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文