C++ Boost:Windows 中对 boost::system::generic_category() 的 undefined reference

标签 c++ boost

我正在尝试在 CodeBlocks 中编译这段代码

#include <boost/filesystem.hpp>
#include <iostream>

using namespace boost::filesystem;

int main()
{


  if ( !boost::filesystem::exists( "myfile.txt" ) )
{
  std::cout << "Can't find my file!" << std::endl;
}
}

有了这个编译标志:

g++.exe -Wall -fexceptions -g -O3 -pedantic-errors -Wall -std=c++0x -lboost_system -IC:\Users\moe\Desktop\boost_1_67_0 -c C:\Users\moe\Desktop\oo\main.cpp -o obj\Debug\main.o

但我总是收到这个错误:

boost::system::generic_category()

这是我在编译代码时收到的错误日志:

Untitled4.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:733: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:736: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:748: undefined reference to `boost::system::generic_category()'
Untitled4.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:703: undefined reference to `boost::system::generic_category()'
C:/Users/moe/Desktop/boost_1_67_0/boost/system/error_code.hpp:706: undefined reference to `boost::system::generic_category()'
Untitled4.o: In function `boost::filesystem::path_traits::convert(char const*, char const*, std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&)':
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/path.hpp:981: undefined reference to `boost::filesystem::path::codecvt()'
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/path.hpp:981: 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, int> const&)'
Untitled4.o: In function `boost::filesystem::exists(boost::filesystem::path const&)':
C:/Users/moe/Desktop/boost_1_67_0/boost/filesystem/operations.hpp:446: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
collect2.exe: error: ld returned 1 exit status

最佳答案

将库放在链接器命令行的末尾:

关于C++ Boost:Windows 中对 boost::system::generic_category() 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50317091/

相关文章:

c++ - Redis 性能问题

c++ - 如何使用存储在 boost spirit 闭包中的变量作为 boost spirit 循环解析器的输入?

multithreading - 虚假解除 boost 线程中的阻塞

c++ - 为什么在 C++ 中分配对象的地址不会改变?

c++ - 为什么内置排序无法对 vector 映射进行排序?

c++ - 获取全局IP地址

c++ - 在列表中正确使用 boost::shared_ptr

c++ - mutex.lock 与 unique_lock

c++ - Microsoft 2010 visual c,安装FLTK

c++ - 是否可以重用 binary_oarchive 实例?