(C++) undefined reference to 'boost::thread::thread()'
August 30, 2019 · View on GitHub
Full error message
/MyFolder/main.o:: In function 'main': /MyFolder/main.cpp:5: error: undefined reference to 'boost::thread::thread()' /MyFolder/main.cpp:5: error: undefined reference to 'boost::thread::~thread()' :: error: collect2: ld returned 1 exit status
Cause
IDE: Qt Creator 1.2.0
Project type: Qt4 Console Application
Libraries used:
- Boost: version 1.40
The following source code was used:
#include <boost/thread.hpp> int main() { boost::thread t; }
The following project file was used:
#------------------------------------------------- # # Project created by QtCreator 2010-07-21T19:37:18 # #------------------------------------------------- QT += core QT -= gui TARGET = MyTarget CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp
Solution
You need to link against the boost::thread library. Add the following line to your project file:
LIBS += -L/usr/local/lib -lboost_thread