编译报错:undefined reference to `boost::filesystem::path::filename() const'

使用boost库编译时,显示如下错误:

CMakeFiles/1.dir/1.cpp.o: In function `categorizer::categorizer(int)':
1.cpp:(.text+0x5b8): undefined reference to `boost::filesystem::path::filename() const'
1.cpp:(.text+0x669): undefined reference to `boost::filesystem::path::filename() const'
CMakeFiles/1.dir/1.cpp.o: In function `categorizer::make_train_set()':
1.cpp:(.text+0xc53): undefined reference to `boost::filesystem::path::filename() const'
1.cpp:(.text+0xcd7): undefined reference to `boost::filesystem::path::filename() const'
CMakeFiles/1.dir/1.cpp.o: In function `categorizer::category_By_svm()':
1.cpp:(.text+0x2bbd): undefined reference to `boost::filesystem::path::filename() const'
CMakeFiles/1.dir/1.cpp.o:1.cpp:(.text+0x2c1c): more undefined references to `boost::filesystem::path::filename() const' follow
CMakeFiles/1.dir/1.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
1.cpp:(.text+0x41c6): undefined reference to `boost::system::generic_category()'
1.cpp:(.text+0x41d2): undefined reference to `boost::system::generic_category()'
1.cpp:(.text+0x41de): undefined reference to `boost::system::system_category()'
CMakeFiles/1.dir/1.cpp.o: In function `boost::system::error_code::error_code()':
1.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
CMakeFiles/1.dir/1.cpp.o: In function `boost::system::error_code::clear()':
1.cpp:(.text._ZN5boost6system10error_code5clearEv[_ZN5boost6system10error_code5clearEv]+0x17): undefined reference to `boost::system::system_category()'
CMakeFiles/1.dir/1.cpp.o: In function `boost::filesystem::directory_entry::status(boost::system::error_code&) const':
1.cpp:(.text._ZNK5boost10filesystem15directory_entry6statusERNS_6system10error_codeE[_ZNK5boost10filesystem15directory_entry6statusERNS_6system10error_codeE]+0x36): undefined reference to `boost::filesystem::directory_entry::m_get_status(boost::system::error_code*) const'
CMakeFiles/1.dir/1.cpp.o: In function `boost::filesystem::directory_entry::symlink_status(boost::system::error_code&) const':
1.cpp:(.text._ZNK5boost10filesystem15directory_entry14symlink_statusERNS_6system10error_codeE[_ZNK5boost10filesystem15directory_entry14symlink_statusERNS_6system10error_codeE]+0x36): undefined reference to `boost::filesystem::directory_entry::m_get_symlink_status(boost::system::error_code*) const'
CMakeFiles/1.dir/1.cpp.o: In function `boost::filesystem::detail::dir_itr_imp::~dir_itr_imp()':
1.cpp:(.text._ZN5boost10filesystem6detail11dir_itr_impD2Ev[_ZN5boost10filesystem6detail11dir_itr_impD5Ev]+0x24): undefined reference to `boost::filesystem::detail::dir_itr_close(void*&, void*&)'
CMakeFiles/1.dir/1.cpp.o: In function `boost::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const&)':
1.cpp:(.text._ZN5boost10filesystem18directory_iteratorC2ERKNS0_4pathE[_ZN5boost10filesystem18directory_iteratorC5ERKNS0_4pathE]+0x57): undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
CMakeFiles/1.dir/1.cpp.o: In function `boost::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const&, boost::system::error_code&)':
1.cpp:(.text._ZN5boost10filesystem18directory_iteratorC2ERKNS0_4pathERNS_6system10error_codeE[_ZN5boost10filesystem18directory_iteratorC5ERKNS0_4pathERNS_6system10error_codeE]+0x5a): undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
CMakeFiles/1.dir/1.cpp.o: In function `boost::filesystem::directory_iterator::increment()':
报错原因:没有链接动态库文件

 

解决方案:使用g++ `pkg-config opencv --cflags` 1.cpp -o 1 `pkg-config opencv --libs` -lboost_thread -lboost_filesystem -lpthread -lboost_system   命令进行编译,即可通过。

有问题欢迎提问!

展开阅读全文

没有更多推荐了,返回首页