Boost logo

Boost Users :

Subject: [Boost-users] error while compiling application that uses a static lib that uses boost
From: ChristinaDRS (mail_at_[hidden])
Date: 2009-04-22 14:58:13


Greetings all,

I have a library called test which has a class that uses boost thread and
mutex. here is how the includes in my .h file look:

#include <boost/thread/mutex.hpp>
#include <boost/thread.hpp>

and here are the private vars:

boost::mutex connectedPeersMutex_;
boost::thread* listenThread_;

in the .cpp file i have I use:

#include <boost/bind.hpp>

Now here is how I built my library with this Makefile:

SRC = test1.cpp test2.cpp
OBJ = $(SRC:.cpp=.o)
OUT = libtest.a
INCLUDES = -I. -I$$BOOST_ROOT
CCFLAGS = -g
CCC = g++
LDFLAGS = -g
.SUFFIXES: .cpp
default: $(OUT)

.cpp.o:
        $(CCC) $(INCLUDES) $(CCFLAGS) -c $< -o $@

$(OUT): $(OBJ)
        ar rcs $(OUT) $(OBJ)

clean:
        rm -f $(OBJ) $(OUT) Makefile.bak

now I try to build a second application that simply uses the libtest.a like
this:

$ g++ -I ~/boost_1_38_0/ -I. main.cpp -omain -L/usr/local/lib/ -L. -ltest
-lboost_thread-gcc41-mt-1_38
 
./libtest.a(test1.o): In function `test1::StartServer(int,
std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
int)':
/home/chris/test1.cpp:337: undefined reference to
`boost::thread::thread(boost::function0<void,
std::allocator<boost::function_base> > const&)'
./libtest.a(test1.o): In function `~ test1':
/home/chris/test1.cpp:36: undefined reference to `boost::mutex::~mutex()'
/home/chris/test1.cpp:36: undefined reference to `boost::mutex::~mutex()'
/home/chris/test1.cpp:36: undefined reference to `boost::mutex::~mutex()'
/home/chris/test1.cpp:36: undefined reference to `boost::mutex::~mutex()'
/home/chris/test1.cpp:36: undefined reference to `boost::mutex::~mutex()'
./libtest.a(test1.o):/home/chris/test1.cpp:36: more undefined references to
`boost::mutex::~mutex()' follow
./libtest.a(test1.o): In function `test1':
/home/chris/test1.cpp:8: undefined reference to `boost::mutex::mutex()'
/home/chris/test1.cpp:8: undefined reference to `boost::mutex::mutex()'
./libtest.a(test1.o): In function
`boost::detail::thread::lock_ops<boost::mutex>::lock(boost::mutex&)':
/usr/include/boost/thread/detail/lock.hpp:33: undefined reference to
`boost::mutex::do_lock()'
./libtest.a(test1.o): In function
`boost::detail::thread::lock_ops<boost::mutex>::unlock(boost::mutex&)':
/usr/include/boost/thread/detail/lock.hpp:45: undefined reference to
`boost::mutex::do_unlock()'
collect2: ld returned 1 exit status

Any idea why I am getting these undefined references?

Thanks!
Christina

-- 
View this message in context: http://www.nabble.com/error-while-compiling-application-that-uses-a-static-lib-that-uses-boost-tp23175806p23175806.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net