Link issue with condition_variable
Hello, I'm using boost for the first time and I'm struggling to link my program. I've added libboost_pthread-mt to the link link (which got most of the symbols), but I still can't seem to get the symbols for the condition variables. The issue could be with the code, as I find the lock-mutex-condition_variable interactions to be very confusing, but it does appear to be a link issue. Consider the following error message emitted during link command: mpicxx <objects> -D_FILE_OFFSET_BITS=64 -L/lib64 -lfuse -lrt -ldl -lboost_thread-mt -lpthread -o aio_benchmark src/aio/thread_pool_adaptive_writer.o: In function `aio::ThreadPoolWriter::Write(aio::File*, std::vector<int, std::allocator<int> >, void*, unsigned long)': /home/bws/sandbox/aiofs/src/aio/thread_pool_writer.cc:59: undefined reference to `boost::condition_variable::notify_all()' /home/bws/sandbox/aiofs/src/aio/thread_pool_writer.cc:63: undefined reference to `boost::condition_variable::wait(boost::unique_lock<boost::mutex>&)' src/aio/thread_pool_writer.o: In function `aio::ThreadPoolWriter::threadWait()': /home/bws/sandbox/aiofs/src/aio/thread_pool_writer.cc:76: undefined reference to `boost::condition_variable::wait(boost::unique_lock<boost::mutex>&)' /home/bws/sandbox/aiofs/src/aio/thread_pool_writer.cc:110: undefined reference to `boost::condition_variable::notify_one()' Is condition variable in a different library? I am using the boost stuff distributed with Fedora 11: boost-1.37.0-7.fc11.x86_64 boost-devel-1.37.0-7.fc11.x86_64 Cheers, Brad
Bradley W. Settlemyer <settlemyerbw <at> ornl.gov> writes:
/home/bws/sandbox/aiofs/src/aio/thread_pool_writer.cc:110: undefined reference to `boost::condition_variable::notify_one()'
Is condition variable in a different library?
I'm having an identical problem on Ubuntu Karmic with the Boost 1.40 libraries. My code (test.cpp) is: #include <boost/thread/thread.hpp> int main() { boost::condition_variable myCond; myCond.notify_one(); return 0; } I compile with: g++ -lboost_thread-mt test.cpp -o test And get the error: /tmp/ccj08TQK.o: In function `main': boost.cpp:(.text+0x2b): undefined reference to `boost::condition_variable::notify_one()' collect2: ld returned 1 exit status Any suggestions? -- Carl
Carl <carl.fischer <at> laposte.net> writes:
My code (test.cpp) is:
#include <boost/thread/thread.hpp> int main() { boost::condition_variable myCond; myCond.notify_one(); return 0; }
I forgot an include: #include <boost/thread/condition.hpp> Didn't realise that a missing header file would cause issues at the linking stage. Strange how asking for help somehow triggers your brain into finding the solution itself even after several days of thinking about the problem. -- Carl
participants (2)
-
Bradley W. Settlemyer
-
Carl