gcc - 无法链接到提升库

时间:2016-08-04 18:45:22

标签: c++ gcc boost linker

我有一个使用Boost.Filesystem,Boost.Test的项目。 Project包含几个模块 - 静态库(.a)和应用程序。所有模块都成功编译。但是我无法将编译好的文件链接到应用程序中。

例如,我尝试生成具有testapp func的简单main(),并从另外两个静态库中调用函数。

g++ -static test.o -L/../boost/stage/lib -l:libboost_filesystem.a -l:libboost_system.a -L../BuildOutput -l:utilstest.a -l:utils.a -o testapp

对于这个命令,我有很多警告。所有警告都指向Boost.Filesystem的Boost.system。警告看起来像这样:

/../utilstest.a(string_converter_test.o): In function `std::_Function_handler<void (boost::filesystem::path const&), string_converter()::{lambda(boost::filesystem::path const&)#2}>::_M_invoke(std::_Any_data const&, boost::filesystem::path const&)':
string_converter_test.cpp:(.text+0x1695): undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, __mbstate_t> const&)'
/../utils.a(string_generator.o): In function `StringGenerator::remove(boost::filesystem::path const&)':
string_generator.cpp:(.text+0xa00): undefined reference to `boost::system::system_category()'
string_generator.cpp:(.text+0xa10): undefined reference to `boost::filesystem::detail::remove(boost::filesystem::path const&, boost::system::error_code*)'

对于使用Boost.Test的应用程序 - 我也有关于Boost.System和Boost.Filesystem的警告,但没有关于Boost.Test的警告。

我确定gcc可以找到Boost库,但出于某种原因可以与它们链接。

我无法弄清楚出了什么问题。有什么想法吗?

用于编译Boost的命令:

./bootstrap.sh
./b2 toolset=gcc address-model=64 cxxflags="-std=c++11" define=BOOST_SYSTEM_NO_DEPRECATED stage release

用于编译.cpp文件的命令:

g++ -I../XXX -isystem /../boost -m64 -O3 -Wall -Wextra -MMD -std=c++11 -c YYY.cpp -o YYY.o

Ubuntu 16.04,gcc 5.4.0,提升1.61

解决方案 - 更改gcc参数的顺序:g++ -static test.o -L../BuildOutput -l:utilstest.a -l:utils.a -L/../boost/stage/lib -l:libboost_filesystem.a -l:libboost_system.a -o testapp

0 个答案:

没有答案