c++ -/usr/include/boost/filesystem/path.hpp:307: 未定义对`boost::filesystem::path::operator 的引用

标签 c++ linux

我有一些代码,当我编译它时,出现以下错误,我不知道如何解决。我尝试添加 -L/usr/lib/x86_64-linux-gnu-lboost_system-lboost_filesystem,但我仍然得到同样的错误。我现在不知道如何解决这个问题,是否有人可以提供帮助?

Agent.o: In function `boost::filesystem::path::append(char const*, std::codecvt<wchar_t, char, __mbstate_t> const&)':
/usr/include/boost/filesystem/path.hpp:307: undefined reference to `boost::filesystem::path::operator/=(char const*)'
Agent.o: In function `boost::filesystem::exists(boost::filesystem::path const&)':
/usr/include/boost/filesystem/operations.hpp:289: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
Agent.o: In function `boost::filesystem::create_directories(boost::filesystem::path const&)':
/usr/include/boost/filesystem/operations.hpp:399: undefined reference to `boost::filesystem::detail::create_directories(boost::filesystem::path const&, boost::system::error_code*)'
Agent.o: In function `boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<char [256]>::type>, boost::filesystem::path&>::type boost::filesystem::path::operator/=<char [256]>(char const (&) [256])':
/usr/include/boost/filesystem/path.hpp:302: undefined reference to `boost::filesystem::path::codecvt()'
collect2: error: ld returned 1 exit status
make: *** [player] Error 1

相关代码如下

bool Agent::openTupleLog()
{
 std::string dir="~/Experiments/Nov/";
 // create the log directory & file path string


try
{
    boost::filesystem::path kaway_log( dir
#if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION == 2
#  ifndef BOOST_FILESYSTEM_NO_DEPRECATED
                                       , &boost::filesystem::native
#  endif
#endif
                                       );
    if ( ! boost::filesystem::exists( kaway_log )
         && ! boost::filesystem::create_directories( kaway_log ) )
    {
        std::cerr << __FILE__ << ": " << __LINE__
                  << ": can't create log directory '"
                  << kaway_log.BOOST_FS_DIRECTORY_STRING() << "'" << std::endl;
        return false;
    }

    kaway_log /= tuplesFilename;


   M_kaway_log_name = kaway_log.BOOST_FS_FILE_STRING();
}
catch ( std::exception & e )
{
    std::cerr << __FILE__ << ": " << __LINE__
              << " Exception caught! " << e.what()
              << "\nCould not create log directory '"
              << dir
              << "'" << std::endl;
    return false;
}

// open the output file stream
M_kaway_log.open( M_kaway_log_name.c_str() );

if ( ! M_kaway_log.is_open() )
{
    std::cerr << __FILE__ << ": " << __LINE__
              << ": can't open log_file " << M_kaway_log_name
              << std::endl;
    return false;
}

return true;

最佳答案

问题已解决。

我问了一个 friend ,他告诉我在命令末尾添加/usr/lib/x86_64-linux-gnu/libboost_filesystem.a -lboost_filesystem -lboost_system,然后就可以了。他说:

The order of putting those flags are dependent, and thus I have to move the .a to very end. Then it ask for boost_system and thus I appended -lboost_system for its pleasure.

请注意,它是 libboost_filesystem.a,而不是 libboost_filesystem.so

关于c++ -/usr/include/boost/filesystem/path.hpp:307: 未定义对`boost::filesystem::path::operator 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47281362/

相关文章:

c++ - 使用 vector 创建高分系统

c++ - 我如何证明 delete 不会释放 new [] 分配的所有内存?

c++ - Lambda 表达式和内存管理

c++ - 在哪里放置效用函数

c++ - 在 QLabel 中隐藏或裁剪重叠文本?

linux - cent os 6.8如何安装Hugin-2016.2.0?

C++ 无法将 lambda 转换为 std::pair 中的 std::packaged_task

linux - 从 Docker 运行 msi。应该选择哪个主机操作系统

c - 编写简单的 GUI 应用程序?几个注意事项

linux - gnuplot:没有足够的列用于可变颜色