|
我在windows里使用MINGW g++ v4.4 编译有模板的程序,
其中有个用于模板实例化的函数:
#include "grammar_composition.hpp"
// This is not really called. Its only purpose is to
// instantiate the constructor of the grammar.
void instantiate_composition()
{
typedef qi::grammar<iterator_type, attr_class_definition(), locals<int>, white_space<iterator_type> > class_deg_g;
typedef class_modification_grammar<iterator_type> classmodi_g;
classmodi_g * modi = 0;
class_deg_g *class_definition = 0;
composition_grammar<iterator_type> comp(*class_definition, *modi); // 参数是const reference类型的
}
用-O 选项编译没问题,用-O2编译就有 undefined reference这样的错误。
使用 g++ -v -O2 -Q XX.cpp 查看-O2对应的选项,
对比发现是 -O2 隐含增加了 -fipa-cp 选项, 去掉就可以了, 编译时用
g++ -O2 -fno-ipa-cp
而在gcc 4.3.2版本里没有这样的问题
-fipa-cp的作用是:
Perform interprocedural constant propagation. This optimization analyzes the program to determine when values passed to functions are constants and then optimizes accordingly. This optimization can substantially increase performance if the application has constants passed to functions. This flag is enabled by default at -O2, -Os and -O3. |
|