0

I have a problem: I wrote code using Boost (locks.hpp). My server is running x64 Ubuntu (Linux). When i compile this code with -m64, it builds fine. But when I try to compile for -m32, I get these errors:

g++ -fPIC -m32 -shared -Wl,-soname,test.so -ldl -o test.so test.cpp -lboost_thread

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libboost_thread.so when searching for -lboost_thread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libboost_thread.a when searching for -lboost_thread
/usr/bin/ld: skipping incompatible //usr/lib/libboost_thread.so when searching for -lboost_thread
/usr/bin/ld: skipping incompatible //usr/lib/libboost_thread.a when searching for -lboost_thread
/usr/bin/ld: cannot find -lboost_thread
collect2: ld returned 1 exit status

What am I doing wrong? Thanks!

Mysticial
  • 464,885
  • 45
  • 335
  • 332
Robert
  • 507
  • 2
  • 9
  • 20
  • 1
    Whilst I have no experience with G++: is it possible that you have no 32bit version of boost (kinda how I would interpret the "incompatible stuff")... – MFH Jul 08 '12 at 22:04
  • 3
    are you sure you installed the 32 bits boost libraries? – fvu Jul 08 '12 at 22:05
  • @fvu can you give me a command to install 32 bit boost libraries on x64 ubuntu? – Robert Jul 08 '12 at 22:35
  • @Robert no sorry, and when I read this http://askubuntu.com/questions/29665/apt-get-32-bit-package-on-amd64-ubuntu-installation it definitely looks a lot harder than it is on the opensuse I use... – fvu Jul 08 '12 at 22:45

2 Answers2

3

Try installing the 32-bit boost package:

sudo apt-get install libboost-thread-dev:i386 
Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • Unfortunately, this forces replacement of the current 64-bit development env (compiler and many packages) so it is too intrusive. Is there a way to have both 32-bit and 64-bit side by side? – arielf Jul 10 '14 at 00:16
  • @arielf, yes, there is, but I don't know Ubuntu so I don't know how to do it. I'm amazed that the command above _replaces_ anything, rather than just adding a new package. – Jonathan Wakely Jul 10 '14 at 09:13
  • In my experience, this is only an issue with boost. I have many (C language) libraries installed side by side (multi-arch: 32 and 64 bit) with no issues. Not sure why the boost `*-dev:i386` package creators forced it to conflict with the default (amd64) boost `-dev` packages. Since I have several packages already built/installed that depend on the 64-bit version of boost, the `replaces` clause in his `:i386` package, forces the removal of 1) the 64-bit boost version and 2) all the packages that depend on it. :( – arielf Jul 10 '14 at 21:17
  • @arielf, it's not an issue with the Boost packages on the distros I use, I'd request the Ubuntu (or Debian) package maintainers to sort it out – Jonathan Wakely Jul 11 '14 at 09:55
2

You need a 32 bit version of the thread library. The answer to your question is already on stackoverflow.com. Use the address-model option when you build boost from source. Boost provides great documentation for building on Linux.

bjam address-model=32
Community
  • 1
  • 1
Dan
  • 3,485
  • 2
  • 21
  • 25
  • Thanks for your answer. Can you tell me how can i add these compiled headers and libs to g++ command? – Robert Jul 09 '12 at 12:46
  • You could use the boost "bcp" utility: http://www.boost.org/doc/libs/1_50_0/tools/bcp/doc/html/index.html – Dan Jul 10 '12 at 15:39
  • @Dan If I use BCP on a 64-bit machine and move the generated folder to a 32-bit machine, will it still work? – Steven Roose Aug 17 '14 at 12:40
  • 1
    @StevenRoose Yes, it will work. BCP copies copies the source files and dependencies for you; you have to add and build the source files in your project. – Dan Aug 19 '14 at 13:19