c++ - 在 Ubuntu 13.04 上链接 boost::filesystem

标签 c++ gcc boost cmake

我正在尝试将一个项目链接到 Ubuntu 13.04 上的 boost:filesystem,但在最后阶段我遇到了一些奇怪的链接错误。

构建配置是通过 cmake 完成的:

find_package(Boost COMPONENTS system filesystem program_options REQUIRED )
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

target_link_libraries(${YARS_TARGET} yarsLib GLEW GL GLU glut m dl xerces-c ode ${Boost_LIBRARIES})

我尝试使用不同的 boost 版本。对于 1.49 和 1.53,我有相同的行为。 在 Ubuntu 12.04 上,它确实可以正常工作,而在我运行 Archlinux 和 boost 1.53 的开发机器上,它编译、链接和运行都很好。

/usr/bin/g++   -O3    CMakeFiles/yars.dir/yarsMain.o  -o ../bin/yars  
-L/home/vagrant/local/lib -rdynamic ../lib/libyarsLib.a -lGLEW -lGL -lGLU 
-lglut -lm -ldl -lxerces-c -lode -lboost_system 
-lboost_filesystem -lboost_program_options 
../lib/libsensorLib.a ../lib/libenvironmentLib.a ../lib/libutilLib.a ../lib/libutilFilterLib.a ../lib/libutilFormatLib.a ../lib/libutilFunctionGeneratorLib.a ../lib/libutilIoLib.a ../lib/libutilMathLib.a ../lib/libutilDefineLib.a ../lib/libdescriptionLib.a ../lib/libfilterDescriptionLib.a ../lib/libfunctionGeneratorDescriptionLib.a ../lib/libfunctionGeneratorDescriptionUtilLib.a ../lib/libbioDescriptionLib.a ../lib/libsensorsDescriptionLib.a ../lib/libyarsDirectoriesModel.a -Wl,-rpath,/home/vagrant/local/lib: 
    ../lib/libutilIoLib.a(FileSystemOperations.o):
In function `FileSystemOperations::doesDirExist(boost::filesystem::path)':
    FileSystemOperations.cpp:(.text+0x27): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x3a): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    ../lib/libutilIoLib.a(FileSystemOperations.o): In function `FileSystemOperations::doesFileExist(boost::filesystem::path)':
    FileSystemOperations.cpp:(.text+0x67): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x7a): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    ../lib/libutilIoLib.a(FileSystemOperations.o): In function `FileSystemOperations::doesDirExist(std::string*)':
    FileSystemOperations.cpp:(.text+0xca): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    ../lib/libutilIoLib.a(FileSystemOperations.o):FileSystemOperations.cpp:(.text+0xdf): more undefined references to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' follow
    ../lib/libutilIoLib.a(FileSystemOperations.o): In function `FileSystemOperations::getFirstExistingDirContainingDir(std::vector<std::string, std::allocator<std::string> >, std::string*)':
    FileSystemOperations.cpp:(.text+0x2c3): undefined reference to `boost::filesystem::path::root_directory() const'
    FileSystemOperations.cpp:(.text+0x35e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x373): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x403): undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
    FileSystemOperations.cpp:(.text+0x43b): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x453): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x50d): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x564): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    ../lib/libutilIoLib.a(FileSystemOperations.o): In function `FileSystemOperations::getFirstExistingDirContainingFile(std::vector<std::string, std::allocator<std::string> >, std::string*)':
    FileSystemOperations.cpp:(.text+0x7e3): undefined reference to `boost::filesystem::path::root_directory() const'
    FileSystemOperations.cpp:(.text+0x87e): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x893): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x923): undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
    FileSystemOperations.cpp:(.text+0x95b): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x973): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0xa2d): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0xa84): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    ../lib/libutilIoLib.a(FileSystemOperations.o): In function `FileSystemOperations::getFirstExistingDir(std::vector<std::string, std::allocator<std::string> >)':
    FileSystemOperations.cpp:(.text+0xd53): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    ../lib/libutilIoLib.a(FileSystemOperations.o):FileSystemOperations.cpp:(.text+0xd68): more undefined references to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)' follow
    ../lib/libutilIoLib.a(FileSystemOperations.o): In function `FileSystemOperations::checkValidPath(std::string*, bool, bool, std::string)':
    FileSystemOperations.cpp:(.text+0x1100): undefined reference to `boost::filesystem::detail::initial_path(boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x1124): undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
    FileSystemOperations.cpp:(.text+0x11e9): undefined reference to `boost::filesystem::path::root_directory() const'
    FileSystemOperations.cpp:(.text+0x1237): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x130a): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x131f): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x137b): undefined reference to `boost::filesystem::detail::system_complete(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x13dc): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    ../lib/libutilIoLib.a(FileSystemOperations.o): In function `FileSystemOperations::checkValidPathFromAlternatives(std::string*, std::string*, std::vector<std::string, std::allocator<std::string> >*, bool, std::string)':
    FileSystemOperations.cpp:(.text+0x1635): undefined reference to `boost::filesystem::path::root_directory() const'
    FileSystemOperations.cpp:(.text+0x1699): undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
    FileSystemOperations.cpp:(.text+0x16d0): undefined reference to `boost::filesystem::detail::system_complete(boost::filesystem::path const&, boost::system::error_code*)'
    FileSystemOperations.cpp:(.text+0x173f): undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
    collect2: error: ld returned 1 exit status

最佳答案

只是一个建议:

1) 检查你的 boost 库是否包含所需的符号,你可以使用这样的东西: nm -D/usr/lib64/libboost_filesystem.so.1.52.0 |详细信息 | C++过滤器 | grep 你的名字

2)尝试更改链接库的顺序,例如将 -lboost_bla-bla-bla 放在命令行的末尾,然后再次使用 g++ 运行此命令,不要使用 make 或其他东西,只需复制粘贴命令并进行实验与它。

关于c++ - 在 Ubuntu 13.04 上链接 boost::filesystem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17560057/

相关文章:

c++ - 使用 Boost 的 Linux 的 Visual Studio 2017 远程构建

c++ - boost::mpl 变换操作元函数参数错误

c++ - 如何覆盖 boost::serialize 获取指向对象的指针时发生的情况

c# - 设计网站后端——Python 还是 C++/C#?

gcc - 为什么要在项目中使用#include_next?

gcc - gcc 如何知道源代码来自哪里?

c++ - 在多线程应用程序中,我将如何使用原子内置函数来设置/查看 time_t 值?

c++ - 使用 boost mpl 插入器迭代器的意外结果

c++ - C/C++ 测试框架

c++ - 返回 std::vector 时缺少元素