G ++使用-flto选项错误 [英] g++ error using -flto option

查看:2987
本文介绍了G ++使用-flto选项错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使以g链接时优化++。我的程序编译没有在 -flto 选项罚款。当我把它添加到我的Makefile中的目标文件编译没有错误,例如

I am trying to enable link time optimization in g++. My program compiles fine without the -flto option. When I add it to my Makefile the object files compile without errors, e.g.

g++ main.cpp -I ../includes -std=c++0x -fopenmp -Wall -pedantic -Wno-vla -flto -D INFO_ -c -o .obj/main.o

但是,当涉及到程序链接:

But when it comes to link the program:

g++ -fwhole-program -I ../includes -std=c++0x -fopenmp -Wall -pedantic -Wno-vla -flto -D INFO_ .obj/main.o .obj/atom.o .obj/bee.o .obj/colony.o ../includes/.obj/error.o ../includes/.obj/CmdLine.o ../includes/boost_lib_deb/libboost_program_options.a ../includes/gmp_lib_deb/lib/libgmpxx.a ../includes/gmp_lib_deb/lib/libgmp.a -o BeeBench

我得到了很多这样的错误:

I get a lot of errors like these:

includes/gmp_lib_deb/lib/libgmpxx.a ../includes/gmp_lib_deb/lib/libgmp.a -o BeeBench
`typeinfo for boost::program_options::too_many_positional_options_error' referenced in section `.rodata._ZTVN5boost15program_options33too_many_positional_options_errorE[vtable for boost::program_options::too_many_positional_options_error]' of ../includes/boost_lib_deb/libboost_program_options.a(cmdline.o): defined in discarded section `.gnu.linkonce.t._ZTIN5boost15program_options33too_many_positional_options_errorE' of .obj/main.o (symbol from plugin)

`typeinfo for boost::program_options::too_many_positional_options_error' referenced in section `.rodata._ZTIN5boost16exception_detail19error_info_injectorINS_15program_options33too_many_positional_options_errorEEE[typeinfo for boost::exception_detail::error_info_injector<boost::program_options::too_many_positional_options_error>]' of ../includes/boost_lib_deb/libboost_program_options.a(cmdline.o): defined in discarded section `.gnu.linkonce.t._ZTIN5boost15program_options33too_many_positional_options_errorE' of .obj/main.o (symbol from plugin)
`typeinfo for boost::program_options::invalid_command_line_style' referenced in section `.rodata._ZTVN5boost15program_options26invalid_command_line_styleE[vtable for boost::program_options::invalid_command_line_style]' of ../includes/boost_lib_deb/libboost_program_options.a(cmdline.o): defined in discarded section `.gnu.linkonce.t._ZTIN5boost15program_options26invalid_command_line_styleE' of .obj/main.o (symbol from plugin)

我想不出什么错误。我编译使用我的所有目标文件 -flto 。该库,即升压和GMP,都没有 -flto 选项编译。这是造成错误? GCC手册说,它的确定与和放大器混合编译目标文件;没有 -flto 选项。还是我失去了别的东西,比如什么是这个插件的错误是谈论?

I can't figure out what is going wrong. I compile all my object files using -flto. The libs, namely Boost and GMP, are compiled without -flto option. Is this causing the error? The gcc manual says that its ok to mix object files compiled with & without -flto option. Or am I missing something else, for example what is this plugin the error is speaking about?

我在Debian喘息使用G ++ 4.6.3。

I am using G++ 4.6.3 on Debian Wheezy.

更新:

由于在评论中劝我做了一个小例子。我的测试程序的code是只有这个:

As adviced in the comments I made a minimal example. The code of my test program is only this:

#include "boost/program_options.hpp"

int main ( int argC, char* argV[] )
{
    return 0;
}

当我使用编译:

g++ -o test -I ../includes -Wall -std=c++0x test.cpp -flto -fwhole-program -static

如上所述它给了类似的错误。如果我省略了-static,-flto或std = C ++ 0x中选择它编译没有错误。该-fwhole程序选项不会改变结果。我现在还与G ++ 4.7进行测试,同样的错误。

it gives similar errors as described above. If I omit the -static, -flto OR std=c++0x option it compiles without errors. The -fwhole-program option does not change the result. I now also tested with G++ 4.7, same error.

有什么建议?这真的是一个编译器错误,还是我还是做错了什么?

Any suggestions? Is this really a compiler error, or am I still doing something wrong?

推荐答案

由于我没有发现任何证据,这有什么不对我的code,我已经发布了的Boost错误报告。它是由其他用户提振转载为好,因此,我认为它实际上是升压或G ++中的错误。现在有没有来自Boost维护者的回应。当有一个我会更新这个帖子。

Since I found no evidence, that there is something wrong with my code, I have posted a Boost bugreport. It was reproduced by other boost users as well, therefore I think it is actually a bug within boost or the g++. By now there was no response from the Boost maintainer. I'll update this post when there is one.

更新

这似乎是G ++链接器插件引起的问题(不过我不知道为什么)。因此,一个可能的解决办法是使用禁用的链接器插件 -fno使用的连接子插件

It seems like the g++ linker-plugin is causing the problem (Still I have no idea why). Therefore a possible work around is to disable the linker-plugin by using -fno-use-linker-plugin.

这篇关于G ++使用-flto选项错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆