相关疑难解决方法(0)

使用mingw-w64工具链时,Regex Boost库在发布模式下链接会警告"重复部分具有不同的大小"

在发布模式下链接我的项目时,我收到以下警告:

myProject-libs/release/libboost_regex-mt-s-1.50.0.a(cpp_regex_traits.o): duplicate section `.data$_ZZN5boost16cpp_regex_traitsIcE21get_catalog_name_instEvE6s_name[boost::cpp_regex_traits<char>::get_catalog_name_inst()::s_name]' has different size
Run Code Online (Sandbox Code Playgroud)

我怀疑原因可能是boost库的编译方式与我用于项目的选项不同,但我不知道如何找到差异(boost在构建过程中没有输出这些选项).

为了在Ubuntu 12.04上编译win32的boost,我使用了这个过程:

tar jxf boost_1_50_0.tar.bz2
cd boost_1_50_0
./bootstrap.sh
echo "using gcc : 4.6 : i686-w64-mingw32-g++ : <rc>i686-w64-mingw32-windres <archiver>i686-w64-mingw32-ar ;" > user-config.jam
./bjam toolset=gcc target-os=windows --address-model=32 variant=release threading=multi threadapi=win32 link=static runtime-link=static --prefix=/opt/boost_1_50_0-release-static-windows-32 --user-config=user-config.jam -j 10 --without-mpi --without-python -sNO_BZIP2=1 -sNO_ZLIB=1 --layout=tagged install
Run Code Online (Sandbox Code Playgroud)

为了在我的项目中编译文件,我使用类似的东西

i686-w64-mingw32-g++ -march=corei7 -mfpmath=sse -m32 -Wall -fmessage-length=0 -I"/opt/boost_1_50_0-release-static-windows-32/include" -std=c++0x -O3 -g0 -DNDEBUG -I"myProject/src/cpp" -c -o myProject/build/release/src/cpp/myproject.o myproject/src/cpp/myproject.cpp
Run Code Online (Sandbox Code Playgroud)

我的测试表明正则表达式运行良好,但我仍然想解决警告.

编辑

我发现可以使用bjam的cxxflags =参数添加boost编译器的其他选项.

示例:bjam cxxflags =' - fPIC'....

也许确保将与我所做的相同参数传递给项目可以解决问题(特别是与链接问题中建议的优化相关的参数).

c++ boost mingw-w64

10
推荐指数
1
解决办法
4252
查看次数

在使用大小优化(-Os)编译boost_regex时出现"重复部分"错误

编译器:http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.7.2/32-bit/threads-posix/sjlj/x32-4.7.2-release-posix-sjlj-rev6. 7Z

提升:http://sourceforge.net/projects/boost/files/boost/1.52.0/boost_1_52_0.7z

(都在D:驱动器上)

boost_regex编译用:

b2 --prefix=D:\boost toolset=gcc --with-regex --layout=tagged release
Run Code Online (Sandbox Code Playgroud)

码:

#include <boost\regex.hpp>
int main() {
  boost::regex reg("[a-z]+");
}
Run Code Online (Sandbox Code Playgroud)

用参数编译:

g++ -I "d:\boost" -Os -o test.exe test.cpp -static -L d:\boost\stage\lib -lboost_regex-mt
Run Code Online (Sandbox Code Playgroud)

错误:

d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTVN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE[__ZTSN5boost16exception_detail10clone_implINS0_19error_info_injectorISt13runtime_errorEEEE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail10clone_baseE[__ZTSN5boost16exception_detail10clone_baseE]' has different size
d:\boost\stage\lib\libboost_regex-mt.a(regex.o): duplicate section `.rdata$_ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE[__ZTSN5boost16exception_detail19error_info_injectorISt13runtime_errorEE]' has different size
Run Code Online (Sandbox Code Playgroud)

它编译好,但我还没有测试它是否适用于更复杂的代码.删除-Os交换机会清除错误,但应用程序大小会大2倍.

也许我也应该使用大小优化来构建Boost,但我不知道在b2命令行中将该选项传递到何处.

boost mingw compiler-optimization

10
推荐指数
2
解决办法
5398
查看次数

标签 统计

boost ×2

c++ ×1

compiler-optimization ×1

mingw ×1

mingw-w64 ×1