[gelöst] boost::thread statisch linken
-
Wenn ich (unter Ubuntu mit Code::Blocks(g++)) versuche, boost::thread (vers. 1.41) statisch zu linken (libboost_thread-mt.a), bekomme ich einen Haufen Linkerfehler. Dynamisch linken geht ohne Probleme. BOOST_THREAD_USE_DLL oder BOOST_DYN_LINK sind übrigens nicht definiert.
Woran liegt das und wie behebe ich die Fehler?
Die Fehler:
/1_41/lib/libboost_thread-mt.a(thread.o)||In function
boost::detail::(anonymous namespace)::create\_current\_thread\_tls\_key()':| thread.cpp:(.text+0xa6)||undefined reference to
pthread_key_create'|
/1_41/lib/libboost_thread-mt.a(thread.o)||In functionT.910':| thread.cpp:(.text+0x1a0)||undefined reference to
pthread_key_create'|
/1_41/lib/libboost_thread-mt.a(thread.o)||In functionboost::detail::get\_current\_thread_data()':| thread.cpp:(.text+0x224)||undefined reference to
pthread_getspecific'|
/1_41/lib/libboost_thread-mt.a(thread.o)||In functionboost::detail::set\_current\_thread\_data(boost::detail::thread\_data_base*)':| thread.cpp:(.text+0x49b)||undefined reference to
pthread_setspecific'|
/1_41/lib/libboost_thread-mt.a(thread.o)||In functionboost::thread::detach()':| thread.cpp:(.text+0x60f)||undefined reference to
pthread_detach'|
/1_41/lib/libboost_thread-mt.a(thread.o)||In functionboost::thread::start_thread()':| thread.cpp:(.text+0x743)||undefined reference to
pthread_create'|
/1_41/lib/libboost_thread-mt.a(thread.o)||In functionthread_proxy':| thread.cpp:(.text+0x918)||undefined reference to
pthread_setspecific'|
thread.cpp:(.text+0x948)||undefined reference topthread_setspecific'| /1\_41/lib/libboost\_thread-mt.a(thread.o)||In function
boost::(anonymous namespace)::make_external_thread_data()':|
thread.cpp:(.text+0x1ce4)||undefined reference topthread_setspecific'| /1\_41/lib/libboost\_thread-mt.a(thread.o)||In function
boost::thread::timed_join(boost::posix_time::ptime const&)':|
thread.cpp:(.text+0x27df)||undefined reference topthread_join'| /1\_41/lib/libboost\_thread-mt.a(thread.o)||In function
boost::thread::join()':|
thread.cpp:(.text+0x2b24)||undefined reference topthread_join'| /1\_41/lib/libboost\_thread-mt.a(once.o)||In function
boost::detail::get_once_per_thread_epoch()':|
once.cpp:(.text+0x17)||undefined reference topthread_once'| once.cpp:(.text+0x24)||undefined reference to
pthread_getspecific'|
once.cpp:(.text+0x53)||undefined reference topthread_setspecific'| /1\_41/lib/libboost\_thread-mt.a(once.o)||In function
create_epoch_tss_key':|
once.cpp:(.text+0x86)||undefined reference to `pthread_key_create'|
||=== Build finished: 15 errors, 0 warnings ===|
-
du musst die PTHREADS library noch dazulinken, da Boost.Thread auf diese aufbaut.
da ich keine ahnung von linux und nur wenig von GCC habe kann ich dir leider die nötigen switches nicht sagen. google sollte helfen
-
Vielen Dank schonmal. Leider bekomme ich mit der libpthread.a jetzt neue Fehler:
/usr/lib/libpthread.a(pthread_create.o)||In function
allocate\_stack':| /build/buildd/eglibc-2.10.1/nptl/allocatestack.c|444|undefined reference to
_dl_stack_flags'|
/build/buildd/eglibc-2.10.1/nptl/allocatestack.c|586|undefined reference to\_dl\_stack_flags'| /usr/lib/libpthread.a(ptw-nanosleep.o)||In function
__nanosleep_nocancel':|
(.text+0x24)||undefined reference to\_\_syscall\_error'| /usr/lib/libpthread.a(ptw-nanosleep.o)||In function
__nanosleep_nocancel':|
(.text+0x52)||undefined reference to\_\_syscall\_error'| /usr/lib/libpthread.a(ptw-pause.o)||In function
__pause_nocancel':|
(.text+0x18)||undefined reference to\_\_syscall\_error'| /usr/lib/libpthread.a(ptw-pause.o)||In function
__pause_nocancel':|
(.text+0x3b)||undefined reference to\_\_syscall\_error'| /usr/lib/libpthread.a(nptl-init.o)||In function
__pthread_initialize_minimal_internal':|
/build/buildd/eglibc-2.10.1/nptl/nptl-init.c|277|undefined reference to\_\_libc\_setup_tls'| /build/buildd/eglibc-2.10.1/nptl/nptl-init.c|437|undefined reference to
_dl_init_static_tls'|
/build/buildd/eglibc-2.10.1/nptl/nptl-init.c|439|undefined reference to\_dl\_wait\_lookup\_done'| /usr/lib/libpthread.a(ptw-read.o)||In function
__read_nocancel':|
(.text+0x26)||undefined reference to\_\_syscall\_error'| /usr/lib/libpthread.a(ptw-read.o)||In function
__read_nocancel':|
(.text+0x56)||undefined reference to\_\_syscall\_error'| /usr/lib/libpthread.a(ptw-open.o)||In function
__open_nocancel':|
(.text+0x26)||undefined reference to\_\_syscall\_error'| /usr/lib/libpthread.a(ptw-open.o)||In function
__open_nocancel':|
(.text+0x56)||undefined reference to\_\_syscall\_error'| /usr/lib/libpthread.a(sigaction.o)||In function
__libc_sigaction':|
/build/buildd/eglibc-2.10.1/nptl/../sysdeps/unix/sysv/linux/i386/sigaction.c|83|undefined reference to `_dl_sysinfo_dso'|
||=== Build finished: 14 errors, 0 warnings ===|
-
Die _dl_* Symbole sind von libdl (Dynamischer Lader).
Die _syscall_* ??? keine Ahnung, meines Wissens sollten die zur libc gehören.
-
Dieser Thread wurde von Moderator/in rüdiger aus dem Forum Rund um die Programmierung in das Forum Compiler- und IDE-Forum verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Mit libdl und libc kompiliert und linkt er anstandslos, danke!
Leider bekomme ich jetzt beim Ausführen immer einen Segfault-Error (auch wenn ich keinerlei boost-Funktionen nutze).
Callstack:#0 0x804d4eb __libc_start_main() (??:??)
#1 0x804d301 _start() (../sysdeps/i386/elf/start.S : 119)Ich finde bei mir übrigens keinen Ordner "sysdeps".
-
Wie schaut denn der Compiler/Linker-Aufruf aus?
-
Bitte:
-------------- Build: Debug in threads1 ---------------
g++-4.4 -Wall -fexceptions -g -I/boost/linux/1_41_0/include -c /threads1/main.cpp -o obj/Debug/main.o
g++-4.4 -o bin/Debug/threads1 obj/Debug/main.o /boost/linux/1_41/lib/libboost_thread-mt.a /usr/lib/libpthread.a /usr/lib/libc.a /usr/lib/libdl.a
Output size is 987,65 KB
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warningsMir scheint ein Fehler in der libc.a vorzuliegen, denn wenn ich sie zu einem beliebigen anderen Projekt dazulinke, bekomme ich ebenfalls einen Segmentation Fault.
Ich habe sie daher mal hochgeladen: http://www.file-upload.net/download-2250425/libc.a.html
Das libc6-dev-Paket neu zu installieren hat nicht geholfen.
-
Ich habe bei mir in /usr/lib/ noch eine libc_nonshared.a gefunden. Wenn ich die statt der libc.a verwende bekomme ich aber wieder die Linkerfehler.
Hat hier irgendjemand Ubuntu und könnte mal die /usr/lib/libc.a zu einem beliebigen Projekt dazulinken um zu testen, ob dieses Problem nur bei mir auf auftritt?
-
g++ -static -pthread -lboost_thread-mt main.o -o main
-
Herzlichen Dank.
Die -static Option lässt es mit der libpthread.a erfolgreich kompilieren und laufen.