Hello I'm trying to link with boost to use the threading library, but can not seem to get it built.
I installed boost with HomeBrew (mac package installer) and it is in the /usr/local/Cellar/boost/1.50.0
directory.
My main file is very simple right now...
#include <iostream>
#include <boost/thread.hpp>
My make file is like this:
CC = g++
BASE_FLAGS = -m32 -wAll
# INCLUDE BASE DIRECTORY AND BOOST DIRECTORY FOR HEADERS
LDFLAGS = -I/usr/local/Cellar/boost/1.50.0/include -I/opt/local/include
# INCLUDE BASE DIRECTORY AND BOOST DIRECTORY FOR LIB FILES
LLIBFLAGS = -L/usr/local/Cellar/boost/1.50.0/
# SPECIFIY LINK OPTIONS
LINKFLAGS = -l boost_thread-mt -lboost_system
# FINAL FLAGS -- TO BE USED THROUGHOUT
FLAGS = $(BASE_FLAGS) $(LLIBFLAGS) $(LDFLAGS) $(LINKFLAGS)
# NOTE FOR BOOST -- YOU ONLY NEED TO INCLUDE THE PATH BECAUSE IT ONLY INSTALLS HEADER FILES
main: main.cpp
$(CC) $(FLAGS) -o main.out main.cpp
And when I run this, I get a library not found for boost_system. If i take out the boost_system, then I get an error that looks like this:
ld: warning: ignoring file /usr/local/lib/libboost_thread-mt.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /usr/local/lib/libboost_thread-mt.dylib
Undefined symbols for architecture i386:
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccKwJWzr.o
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccKwJWzr.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make: *** [main] Error 1
IF you have just used brew install boost
with no options, this builds a 64-bit binary - both static and dynamic.
Your main culprit from the code above is the use of -m32
option, remove this and you should be okay. This means you are trying to link a 32-bit build against a 64-bit library.
The Boost libraries are symbolic linked to the actual binaries and headers in /usr/local/Cellar/
- (/usr/local/lib
and /usr/local/include
). Your PATH should include these, so no need to specify these in your makefile.
Note that brew (by extension gcc) generally builds 64-bit binaries by default, which from your error output the Boost libraries have been built on. (you can check which architecture a library is by using these tools otool
, file
or lipo
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With