我集成测试环境搭建过程中遇到这个错误:
Linking...
test.obj : error LNK2005: "int g_iBlankLineNum" (?g_iBlankLineNum@@3HA) already defined in countertest.obj
test.obj : error LNK2005: "int g_iCodeLineNum" (?g_iCodeLineNum@@3HA) already defined in countertest.obj
test.obj : error LNK2005: "int g_iCommLineNum" (?g_iCommLineNum@@3HA) already defined in countertest.obj
test.obj : error LNK2005: "int g_iTotalLineNum" (?g_iTotalLineNum@@3HA) already defined in countertest.obj
test.obj : error LNK2005: "int g_bStatBlankLineFlag" (?g_bStatBlankLineFlag@@3HA) already defined in countertest.obj
test.obj : error LNK2005: "int g_bStatCodeLineFlag" (?g_bStatCodeLineFlag@@3HA) already defined in countertest.obj
test.obj : error LNK2005: "int g_bStatCommLineFlag" (?g_bStatCommLineFlag@@3HA) already defined in countertest.obj
test.obj : error LNK2005: "int g_bStatTotalLineFlag" (?g_bStatTotalLineFlag@@3HA) already defined in countertest.obj
Debug/countertest.exe : fatal error LNK1169: one or more multiply defined symbols found
执行 link.exe 时出错.
我估计是g_iBlankLineNum,g_iCodeLineNum,g_iCommLineNum,g_iTotalLineNum,g_bStatBlankLineFlag,g_bStatCodeLineFlag,g_bStatCommLineFlag,g_bStatTotalLineFlag这8个变量在不同的地方被定义了多次,你找一下。如果前一个地方定义了,后一个地方用extern 引用一下就行了,例如:extern int g_iBlankLineNum;