gcc 编译带有大量模板参数的模板类时出错
Posted
技术标签:
【中文标题】gcc 编译带有大量模板参数的模板类时出错【英文标题】:gcc error compiling templated classes with large number of template arguments 【发布时间】:2011-09-13 09:11:55 【问题描述】:我在编译具有嵌套在其他模板类中的模板类的代码时遇到问题。名为 MyClass
的主要模板类有 50 个模板参数,接受名为 null_type_nn
的默认类类型,不做任何具体操作。
我的模板参数都以 '_' 字符开头,如下所示
template<
class T0=null_type_0
, class T1=null_type_1
, ...
, class T50=null_type_50
> MyClass;
typedef MyClass< _MyClassB, _MyClassC > _MyClass1;
typedef MyClass< _MyClassD, _MyClassE > _MyClass2;
.....
typedef MyClass< _MyClass1, _MyClass2, _MyClass3 , ..._MyClass50> my_type_a;
如果我不调用类的某个成员函数,则不会出现以下错误;如果我只是构造一条消息,然后访问/使用它的一个数据成员,我没有问题。
我能做些什么来解决它或帮助编译器完成它的工作?
: Assembler messages:
:8851: Error: symbol `_ZN12mine_structIL10EncodingID5015ELS0_1011E11
AsciiStringLS0_1115E23AsciiAlphaNumericStringLS0_1130ES2_LS0_1019E6S
Int16LS0_1066ES2_LS0_5030E11mine_unionILm1ES_ILS0_5042ELS0_15ES1_
LS0_16404E11mine_arrayILm4ES_ILS0_20ELS0_18ES2_LS0_1078ES3_LS0_2ES3_
LS0_19E5Dec32LS0_16E6SInt32LS0_64005E12mine_null_5LS0_64006E12
mine_null_6LS0_64007E12mine_null_7LS0_64008E12mine_null_8LS0_64009E12
mine_null_9LS0_64010E13mine_null_10LS0_64011E13mine_null_11LS0_64012E13
mine_n...// continues..it is a very big error!
完整的错误日志如下
: Assembler messages:
:972: Error: symbol
_ZN12main_structIL10EncodingID5067ELS0_5037ES_ILS0_5037ELS0_1099E6SInt16LS0_1059ES1_LS0_1036E6SInt64LS0_1037ES2_LS0_1089E6SInt32LS0_1070E10ByteStreamLS0_1095ES3_LS0_1183ES2_LS0_1184ES2_LS0_64009E12main_null_9LS0_64010E13main_null_10LS0_64011E13main_null_11LS0_64012E13main_null_12LS0_64013E13main_null_13LS0_64014E13main_null_14LS0_64015E13main_null_15LS0_64016E13main_null_16LS0_64017E13main_null_17LS0_64018E13main_null_18LS0_64019E13main_null_19LS0_64020E13main_null_20LS0_64021E13main_null_21LS0_64022E13main_null_22LS0_64023E13main_null_23LS0_64024E13main_null_24LS0_64025E13main_null_25LS0_64026E13main_null_26LS0_64027E13main_null_27LS0_64028E13main_null_28LS0_64029E13main_null_29LS0_64030E13main_null_30LS0_64031E13main_null_31LS0_64032E13main_null_32LS0_64033E13main_null_33LS0_64034E13main_null_34LS0_64035E13main_null_35LS0_64036E13main_null_36LS0_64037E13main_null_37LS0_64038E13main_null_38LS0_64039E13main_null_39LS0_64040E13main_null_40LS0_64041E13main_null_41LS0_64042E13main_null_42LS0_64043E13main_null_43LS0_64044E13main_null_44LS0_64045E13main_null_45LS0_64046E13main_null_46LS0_64047E13main_null_47LS0_64048E13main_null_48ELS0_21449E11main_unionILm50ES_ILS0_5016ELS0_1038ES3_LS0_1118ES3_LS0_1017ES3_LS0_1051ES3_LS0_1048ES3_LS0_1014E4DateLS0_1087ES3_LS0_1159ES2_LS0_1008E11AsciiStringLS0_21468E11main_arrayILm4ES_ILS0_5084ELS0_1179ES1C_LS0_1180E23AsciiAlphaNumericStringLS0_64002E12main_null_2LS0_64003E12main_null_3LS0_64004E12main_null_4LS0_64005E12main_null_5LS0_64006E12main_null_6LS0_64007E12main_null_7LS0_64008E12main_null_8LS0_64009ES5_LS0_64010ES6_LS0_64011ES7_LS0_64012ES8_LS0_64013ES9_LS0_64014ESA_LS0_64015ESB_LS0_64016ESC_LS0_64017ESD_LS0_64018ESE_LS0_64019ESF_LS0_64020ESG_LS0_64021ESH_LS0_64022ESI_LS0_64023ESJ_LS0_64024ESK_LS0_64025ESL_LS0_64026ESM_LS0_64027ESN_LS0_64028ESO_LS0_64029ESP_LS0_64030ESQ_LS0_64031ESR_LS0_64032ESS_LS0_64033EST_LS0_64034ESU_LS0_64035ESV_LS0_64036ESW_LS0_64037ESX_LS0_64038ESY
:8191: Error: symbol
_ZN12main_structIL10EncodingID5067ELS0_5037ES_ILS0_5037ELS0_1099E6SInt16LS0_1059ES1_LS0_1036E6SInt64LS0_1037ES2_LS0_1089E6SInt32LS0_1070E10ByteStreamLS0_1095ES3_LS0_1183ES2_LS0_1184ES2_LS0_64009E12main_null_9LS0_64010E13main_null_10LS0_64011E13main_null_11LS0_64012E13main_null_12LS0_64013E13main_null_13LS0_64014E13main_null_14LS0_64015E13main_null_15LS0_64016E13main_null_16LS0_64017E13main_null_17LS0_64018E13main_null_18LS0_64019E13main_null_19LS0_64020E13main_null_20LS0_64021E13main_null_21LS0_64022E13main_null_22LS0_64023E13main_null_23LS0_64024E13main_null_24LS0_64025E13main_null_25LS0_64026E13main_null_26LS0_64027E13main_null_27LS0_64028E13main_null_28LS0_64029E13main_null_29LS0_64030E13main_null_30LS0_64031E13main_null_31LS0_64032E13main_null_32LS0_64033E13main_null_33LS0_64034E13main_null_34LS0_64035E13main_null_35LS0_64036E13main_null_36LS0_64037E13main_null_37LS0_64038E13main_null_38LS0_64039E13main_null_39LS0_64040E13main_null_40LS0_64041E13main_null_41LS0_64042E13main_null_42LS0_64043E13main_null_43LS0_64044E13main_null_44LS0_64045E13main_null_45LS0_64046E13main_null_46LS0_64047E13main_null_47LS0_64048E13main_null_48ELS0_21449E11main_unionILm50ES_ILS0_5016ELS0_1038ES3_LS0_1118ES3_LS0_1017ES3_LS0_1051ES3_LS0_1048ES3_LS0_1014E4DateLS0_1087ES3_LS0_1159ES2_LS0_1008E11AsciiStringLS0_21468E11main_arrayILm4ES_ILS0_5084ELS0_1179ES1C_LS0_1180E23AsciiAlphaNumericStringLS0_64002E12main_null_2LS0_64003E12main_null_3LS0_64004E12main_null_4LS0_64005E12main_null_5LS0_64006E12main_null_6LS0_64007E12main_null_7LS0_64008E12main_null_8LS0_64009ES5_LS0_64010ES6_LS0_64011ES7_LS0_64012ES8_LS0_64013ES9_LS0_64014ESA_LS0_64015ESB_LS0_64016ESC_LS0_64017ESD_LS0_64018ESE_LS0_64019ESF_LS0_64020ESG_LS0_64021ESH_LS0_64022ESI_LS0_64023ESJ_LS0_64024ESK_LS0_64025ESL_LS0_64026ESM_LS0_64027ESN_LS0_64028ESO_LS0_64029ESP_LS0_64030ESQ_LS0_64031ESR_LS0_64032ESS_LS0_64033EST_LS0_64034ESU_LS0_64035ESV_LS0_64036ESW_LS0_64037ESX_LS0_64038ESY
make: * [unpack_test] Error 1
【问题讨论】:
"_
后跟大写字母" 类型的名称由编译器保留。最好不要使用它们。您还需要提供生成错误的行。
你是认真的吗? 50 个模板参数?!并且您发布的错误不包含任何相关信息。请张贴全文。
显示完整的错误,它是那种“错误:符号long_mangled_symbol_name_here
现在真正的错误信息来了。有时你只需要弄脏你的手并挖掘编译器的混乱输出。不要害怕。它很大,但合乎逻辑。大多数情况下。
大家好。编译器根本没有给我任何行..只是这个大错误..给我几分钟,我会发布它。
@Abruzzo Forte:您应该显示实际的错误消息,其中包含几行几乎没有信息的内容并隐藏了实际问题。错误消息将包含巨大的标识符(您可以删除大部分),然后是工具链不喜欢它的地方
【参考方案1】:
来自 C++ 2003 标准:
17.4.3.2.1 全局名称 [lib.global.names]
某些名称和函数签名集总是保留给 实现:
每个名称都包含双下划线 (_ _) 或以 下划线后跟一个大写字母 (2.11) 保留给 实现任何用途。
_MyClassB
、_MyClassC
... 是保留名称。
【讨论】:
虽然我怀疑这会导致错误,但我希望更严格地执行... 嗨,Matthieu...不幸的是,您是对的..我将所有班级名称从“_MyClass”更新为“MyClass”,但仍然无法正常工作。以上是关于gcc 编译带有大量模板参数的模板类时出错的主要内容,如果未能解决你的问题,请参考以下文章