7

i builded my boost library with bjam, and then moved all the .a files into c:\Server\libs\boost_1_46_0\lib

if i want to compile my program there is some error:

the compile command

g++ -Ic:\Server\libs\boost_1_46_0\ -Lc:\Server\libs\boost_1_46_0\lib\ -lboost_thread-mgw45-mt-1_46 -o try1 try1.cpp

the errors

C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0xe9): undefined
 reference to `_imp___ZN5boost6thread4joinEv'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0x120): undefine
d reference to `_imp___ZN5boost6threadD1Ev'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text+0x138): undefine
d reference to `_imp___ZN5boost6threadD1Ev'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text$_ZN5boost11this_
thread18interruptible_waitEm[boost::this_thread::interruptible_wait(unsigned lon
g)]+0x40): undefined reference to `_imp___ZN5boost11this_thread18interruptible_w
aitEPvNS_6detail7timeoutE'
C:\Users\FEHERG~1\AppData\Local\Temp\ccB46To7.o:try1.cpp:(.text$_ZN5boost6thread
C1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thread_move_tIS4
_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(), boost::di
sable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*
)()> >, boost::thread::dummy*>::type)]+0x23): undefined reference to `_imp___ZN5
boost6thread12start_threadEv'
collect2: ld returned 1 exit status

can anybody help me what is the problem in this problem?

i followed this tutorial: http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html

so this is the source: http://pastebin.com/YqCPLNwU

UPDATE:

i think the error is not lining the library, the error is in the library. i built it with bjam with toolchain=gcc multithread options.

UPDATE

here is the objdump http://pastebin.com/4fpqYb7d

UPDATE

i found that the problem is that the linker wants to link with dynamic linking or something like this.

Code Blocks, MinGW, Boost, and static linking issues

there "Jack Kelly" says that i need to add #define BOOST_THREAD_USE_LIB at the beginning of my source file. but this not helps to me. how can i link a library statically? (the -static not helped as well)

Community
  • 1
  • 1
Gergely Fehérvári
  • 7,811
  • 6
  • 47
  • 74
  • What is the content of try1.cpp? – Vlad Mar 13 '11 at 09:58
  • updated my question! http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html – Gergely Fehérvári Mar 13 '11 at 10:01
  • try to compile with `-Wall`, maybe you'll get some additional useful warnings – Vlad Mar 13 '11 at 10:13
  • nothing more. same errors with `-Wall` and `-Werror` – Gergely Fehérvári Mar 13 '11 at 10:15
  • @omnosis: Try `objdump -t libboost_thread-mgw45-mt-1_46.a` or whatever is the dump utility in mingw. This should show you a (pretty long) list of functions which are exported in your `.a`. You can grep for the needed function there, to ensure that it's in. – Vlad Mar 13 '11 at 10:27
  • i dont exactly understandd how to dump it. i didnt find any command for dumping a static library. – Gergely Fehérvári Mar 13 '11 at 10:38
  • @omnosis: mingw package (which you seem to use) has objdump, hasn't it? – Vlad Mar 13 '11 at 10:50
  • yes it has. i dumped the object with `objdump -t c:\Server \libs\boost_1_46_0\lib\libboost_thread-mgw45-mt-1_46.a >out.txt` -> http://pastebin.com/4fpqYb7d – Gergely Fehérvári Mar 13 '11 at 11:06
  • @omnosis: You can see the archive contains `[466](sec 1)(fl 0x00)(ty 20)(scl 2) (nx 0) 0x000070b0 __ZN5boost6thread4joinEv`, but not `_imp___ZN5boost6thread4joinEv`. So something is wrong with the library, perhaps it doesn't correspond to the headers/preprocessor switches you are using. – Vlad Mar 13 '11 at 11:13
  • yes. now tryying to get a prebuild version of boost. – Gergely Fehérvári Mar 13 '11 at 11:17

3 Answers3

5

adding #define BOOST_THREAD_USE_LIB at the beginning works.

Remember to link also boost libs listed in the errors (boost system in my case).

Janek Olszak
  • 4,067
  • 1
  • 28
  • 22
2

Move the -lboost_thread-mgw45-mt-1_46 option to the end of the command line (after try1.cpp). (From chat.)

Community
  • 1
  • 1
Thomas Edleson
  • 2,175
  • 1
  • 16
  • 19
1

This might be relevant https://svn.boost.org/trac/boost/ticket/4614

deek0146
  • 962
  • 6
  • 20