即使在链接后也能提高对系统的"Undefined Reference"

Boost "Undefined Reference" to system even after linking

本文关键字:系统 Undefined Reference 链接      更新时间:2023-10-16

我在eclipse cdt窗口中的boost中包含了以下库。

  1. libboost_filesystem-vc100-mt-1_51
  2. libboostrongystem-vc100-mt-1_51

从律师输出的顶部(下面)看,他们似乎联系得很好。然而,我犯了以下错误。

顾问输出/错误:

18:10:00 **** Incremental Build of configuration Debug for project Boost ****
Info: Internal Builder is used for build
g++ "-LC:\Users\Mike\Desktop\Lib\boost_1_51_0\stage\lib" -o Boost.exe "src\Boost.o" -llibboost_filesystem-vc100-mt-1_51 -llibboost_system-vc100-mt-1_51 
srcBoost.o: In function `_static_initialization_and_destruction_0':
C:/Users/Mike/Desktop/Lib/boost_1_51_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'
C:/Users/Mike/Desktop/Lib/boost_1_51_0/boost/system/error_code.hpp:215: undefined reference to `boost::system::generic_category()'
C:/Users/Mike/Desktop/Lib/boost_1_51_0/boost/system/error_code.hpp:216: undefined reference to `boost::system::system_category()'
srcBoost.o: In function `ZN5boost10filesystem9file_sizeERKNS0_4pathE':
C:/Users/Mike/Desktop/Lib/boost_1_51_0/boost/filesystem/operations.hpp:447: undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
srcBoost.o: In function `path<char [9]>':
C:/Users/Mike/Desktop/Lib/boost_1_51_0/boost/filesystem/path.hpp:139: undefined reference to `boost::filesystem::path::codecvt()'
srcBoost.o: In function `ZN5boost10filesystem11path_traits8dispatchISbIwSt11char_traitsIwESaIwEEEEvRKSsRT_RKSt7codecvtIwciE':
C:/Users/Mike/Desktop/Lib/boost_1_51_0/boost/filesystem/path_traits.hpp:174: undefined reference to `boost::filesystem::path_traits::convert(char const*, char const*, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&, std::codecvt<wchar_t, char, int> const&)'
collect2: ld returned 1 exit status

由此看来,系统库没有正确连接/链接。

我的代码:

#include <boost/filesystem.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
    using namespace boost::filesystem;
    file_size("test.txt");
    return 0;
}

我是不是错过了什么?我需要包括其他内容吗?

每个C++编译器都有自己的规则和函数名篡改的实现(将C++函数名转换为ASM或类C函数)
例如,MSVC将boost::system::generic_category转换为?generic_category@system@助推@@YAABVerror_category@12@XZ,但在这种情况下,您使用的是一个DLL,该DLL是使用带有eclipse g++编译器的MSVC2010(vc100)构建的,该编译器具有不同的名称篡改规则,因此它期望在库中找不到其他内容,并生成链接器错误

一般来说,使用DLL中的C++对象是不合法的,该DLL是从与您在项目中使用的编译器不同的编译器编译的,甚至使用使用以前版本编译器编译的DLL也是不合法的。这就是boost将vc100添加到其DLL名称中以通知您只应将其与vc100(MSVC2010)一起使用的原因