我如何 link 将 boost 库添加到我的项目中?
how can i link the boost library to my project?
代码我写好了
#include <iostream>
#include <boost/thread/thread.hpp>
using namespace std;
void f1()
{
cout <<"Hello world, I'm a thread1!"<<endl;
}
int main()
{
boost::thread t1(&f1);
return 0;
}
并在 qt creator 的 pro 文件中添加了字符串
LIBS += -L/usr/lib/x86_64-linux-gnu -lboost_system
我遇到了这些错误
build-test_not_qt_1-Desktop-Debug/main.o:-1: In function boost::detail::thread_data_base::thread_data_base()':
/build-test_not_qt_1-Desktop-Debug/main.o:-1: In function
boost::detail::thread_data_base::thread_data_base()':
build-test_not_qt_1-Desktop-Debug/main.o:-1: In function boost::thread::start_thread()':
build-test_not_qt_1-Desktop-Debug/main.o:-1: In function
boost::thread::start_thread()':
build-test_not_qt_1-Desktop-Debug/main.o:-1: In function boost::thread::~thread()':
build-test_not_qt_1-Desktop-Debug/main.o:-1: In function
boost::thread::~thread()':
build-test_not_qt_1-Desktop-Debug/main.o:-1: In function boost::detail::thread_data<void (*)()>::~thread_data()':
/usr/include/boost/thread/detail/thread.hpp:91: error: undefined reference to
boost::detail::thread_data_base::~thread_data_base()'
(.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[_ZTIN5boost6detail11thread_dataIPFvvEEE]+0x10):-1: error: undefined reference to `typeinfo for boost::detail::thread_data_base'
:-1: error: collect2: error: ld returned 1 exit status
我该如何修复它们?以及如何使应用程序运行?
LIBS += -L/usr/lib/x86_64-linux-gnu -lboost_system -lboost_thread
代码我写好了
#include <iostream>
#include <boost/thread/thread.hpp>
using namespace std;
void f1()
{
cout <<"Hello world, I'm a thread1!"<<endl;
}
int main()
{
boost::thread t1(&f1);
return 0;
}
并在 qt creator 的 pro 文件中添加了字符串
LIBS += -L/usr/lib/x86_64-linux-gnu -lboost_system
我遇到了这些错误
build-test_not_qt_1-Desktop-Debug/main.o:-1: In function
boost::detail::thread_data_base::thread_data_base()': /build-test_not_qt_1-Desktop-Debug/main.o:-1: In function
boost::detail::thread_data_base::thread_data_base()': build-test_not_qt_1-Desktop-Debug/main.o:-1: In functionboost::thread::start_thread()': build-test_not_qt_1-Desktop-Debug/main.o:-1: In function
boost::thread::start_thread()': build-test_not_qt_1-Desktop-Debug/main.o:-1: In functionboost::thread::~thread()': build-test_not_qt_1-Desktop-Debug/main.o:-1: In function
boost::thread::~thread()': build-test_not_qt_1-Desktop-Debug/main.o:-1: In functionboost::detail::thread_data<void (*)()>::~thread_data()': /usr/include/boost/thread/detail/thread.hpp:91: error: undefined reference to
boost::detail::thread_data_base::~thread_data_base()' (.rodata._ZTIN5boost6detail11thread_dataIPFvvEEE[_ZTIN5boost6detail11thread_dataIPFvvEEE]+0x10):-1: error: undefined reference to `typeinfo for boost::detail::thread_data_base' :-1: error: collect2: error: ld returned 1 exit status
我该如何修复它们?以及如何使应用程序运行?
LIBS += -L/usr/lib/x86_64-linux-gnu -lboost_system -lboost_thread