简体   繁体   English

Dev-C ++ / TDM-GCC:Boost Libaries的链接问题从boost.org下载

[英]Dev-C++/TDM-GCC: Linkage Problems with Boost Libaries Downloaded from boost.org

I'm trying to use regex in Dev-C++ (tdm-gcc 4.7.1). 我正在尝试在Dev-C ++中使用regex (tdm-gcc 4.7.1)。

I've downloaded Boost libraries from boost.org and unpack to 我从boost.org下载了Boost库并解压缩到

C:\Program Files (x86)\Dev-Cpp\boost

And in Dev-C++ added 并在Dev-C ++中添加

C:\Program Files (x86)\Dev-Cpp\boost\libs

to libraries. 到图书馆。

Include paths (C/C++): 包含路径(C / C ++):

C:\Program Files (x86)\Dev-Cpp\boost

main.cpp : main.cpp

#include <boost/regex.hpp> 
using namespace boost; 
int main()
{
   string s ("some txt PING :665454 some_text");
   smatch mt;
  regex r ("PING :(\\d+) "); // error

    system( "pause" );
    return 0;
}

Error: 错误:

D:\programowanie\dev-c++\main12\main.o  main.cpp:(.text$_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE[_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE]+0xc3): undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
D:\programowanie\dev-c++\main12\main.o  main.cpp:(.text$_ZN5boost9re_detail11raw_storage6extendEy[_ZN5boost9re_detail11raw_storage6extendEy]+0x60): undefined reference to `boost::re_detail::raw_storage::resize(unsigned long long)'
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe    main12/main.o: bad reloc address 0x60 in section `.text$_ZN5boost9re_detail11raw_storage6extendEy[_ZN5boost9re_detail11raw_storage6extendEy]'
c:\program files (x86)\dev-cpp\mingw64\x86_64-w64-mingw32\bin\ld.exe    final link failed: Invalid operation
D:\programowanie\dev-c++\collect2.exe   [Error] ld returned 1 exit status

I don't think you could have downloaded binaries from Boost exactly targeting TDM-GCC. 我不认为您可以从Boost下载完全针对TDM-GCC的二进制文件。 As a result, no matter what, you'll hit a classical problem with name mangling which is different across compilers/toolchains. 因此,无论如何,您将遇到名称修改的经典问题,这在编译器/工具链中是不同的。 If you downloaded from Boost binaries , then it's clearly written that these binaries were built with MSVC, and therefore now you have trouble directly linking to these Boost libraries with TDM-GCC because of different name mangling conventions. 如果您从Boost二进制文件下载,那么很明显这些二进制文件是使用MSVC构建的,因此现在您无法使用TDM-GCC直接链接到这些Boost库,因为它们具有不同的名称修改约定。

You have 3 options: 你有3个选择:

  1. Use MSVC to build your project; 使用MSVC构建项目;
  2. Build Boost libraries from source yourself with your current toolchain, ie TDM-GCC; 使用您当前的工具链(即TDM-GCC)从源代码构建Boost库;
  3. Use my builds of Boost libraries - Boost for Windows (latest version is 1.54.0) for latest MinGW-w64 toolchains (currently 2 variants). 使用我的Boost库版本 - Boost for Windows (最新版本为1.54.0),用于最新的MinGW-w64工具链(目前有2个版本)。 So, in addition to binaries, you'd have to download the corresponding toolchain variant of MinGW-w64 (link are there as well) and use it to build your project. 因此,除了二进制文件之外,您还必须下载MinGW-w64的相应工具链变体(链接也在那里)并使用它来构建您的项目。

    NOTE: Although you can build and link your project against my binaries with your TDM-GCC because name mangling is the same (since TDM-GCC is just a derivative of MinGW-w64), the resulting application will be subject to crashes as binaries produced by MinGW-w64 are binary incompatible with TDM-GCC due to patching policies of TDM-GCC. 注意:尽管您可以使用TDM-GCC构建项目并将其链接到我的二进制文件,因为名称修改是相同的(因为TDM-GCC只是MinGW-W64的衍生版本),因此生成的二进制文件将导致崩溃由于TDM-GCC的修补策略,MinGW-W64与TDM-GCC二进制不兼容。

Finally, as stated in comments already, it's not enough just to set paths where Boost libraries can be found, but it is also necessary to explicitly tell the compiler which library you want to link your project against. 最后,正如评论中所述,仅仅设置可以找到Boost库的路径是不够的,但是还必须明确告诉编译器要将项目链接到哪个库。 For the GCC family of compilers (MinGW, MinGW-w64, TDM-GCC) it is done with the -l switch. 对于GCC系列编译器(MinGW,MinGW-w64,TDM-GCC),它使用-l开关完成。 So find where you can specify linker options in Dev-C++ for your project, and add -lboost_regex . 因此,找到可以在Dev-C ++中为项目指定链接器选项的位置,并添加-lboost_regex It will instruct the compiler to fetch libboost_regex.a from the library search paths (that you've already specified) and link to your project. 它将指示编译器从库搜索路径(您已经指定)获取libboost_regex.a并链接到您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM