我们有一个交叉编译的visual studio Makefile项目。我们已经不得不引入solution similar to this来识别编译器错误。 IE浏览器。我们引入了一个Perl脚本来解析GCC的输出并将其转换为Visual Studio将理解的形式。如果我们宣布:
int succ = thisRandomFunction(userPointer, 1, 1);
没有thisRandomFunction
的定义,那么我们将得到链接器错误:
1> ./program.a(taskqueue.o): In function `TaskQueueAdd': 1>
D:\Git\program\taskqueue.c(94,1) : undefined reference to `thisRandomFunction' 1>
collect2: ld returned 1 exit status 1> make: *** [program.exe] Error 1
但是Visual Studio实际上并不认为这是一个错误。具有相同问题的Visual Studio C ++控制台程序具有链接器错误:
1> TestUndefinedReference.cpp
1>TestUndefinedReference.obj : error LNK2019: unresolved external symbol "int __cdecl something(int)" (?something@@YAHH@Z) referenced in function _main
1>D:\Projects\New folder\TestUndefinedReference\Debug\TestUndefinedReference.exe : fatal error LNK1120: 1 unresolved externals
使用此转换器:
sub parseLinkerError
{
my $str = $_[0];
my $find = "undefined reference to";
my $replace = "error LNK2019: unresolved external symbol";
$str =~ s/$find/$replace/g;
return $str
}
我们可以转换这个:
1> d:\Git\program/taskqueue.c:94: undefined reference to `thisRandomFunction'
进入这个
1> D:/Git/eV+/program/taskqueue.c(94,1) error LNK2019: unresolved external symbol `thisRandomFunction'
但这并不足以欺骗visual studio链接器错误解释器。 查看链接器错误的最低要求是什么?是否有任何解决方案可以在不直接解析文本的情况下工作?
答案 0 :(得分:1)
根据the documentation ...
输出的格式应为:
{filename (line# [, column#]) | toolname} :
[any text] {error | warning} code####: localizable string
其中:
例如:
C:\sourcefile.cpp(134) : error C2143: syntax error : missing ';' before '}'
LINK : fatal error LNK1104: cannot open file 'somelib.lib'
<小时/> 您的样本失败,因为它缺少必需的冒号
D:/Git/eV+/program/taskqueue.c(94,1) error LNK2019: unresolved external symbol `thisRandomFunction'
^
答案 1 :(得分:0)
所以似乎添加这一行就足够了:
taskqueue.obj : error LNK2019: unresolved external symbol "thisRandomFunction" referenced in function TaskQueueAdd
据我所知,错误将通过以下键检测到:
[*].obj : error LNK2019: unresolved external symbol "[*]" referenced in function [*]
[*]
可以是任何东西或什么都不是(它甚至不需要是实际的功能)。
因此,以下脚本足以解析它:
my $previousUsedInFunction = "";
sub parseLinkerError
{
my $str = $_[0];
my $find = "undefined reference to";
#check that our string contains the undefined reference to substring.
if (index($str, $find) != -1) {
#Use regular expressions to get the important filename.
my $filename = "";
if ($str =~ /\\([a-zA-Z0-9_.]*)\(/) {
$filename = $1;
#replace whatever filename we find with the .obj equivelent.
$filename =~ s/\.cpp$/\.obj/g;
$filename =~ s/\.h$/\.obj/g;
$filename =~ s/\.c$/\.obj/g;
}
#Use regular expressions to find the function name.
my $function = "";
if ($str =~ /\`([a-zA-Z0-9_.()]*)\'/) {
$function = $1;
}
#create the final string similar to what visual studio expects.
my $finalStr = " " . $filename . ' : error LNK2019: unresolved external symbol "' . $function . '" referenced in function ' . $previousUsedInFunction . "\n";
return $finalStr;
}
return $str;
}
使用以下if语句在主解析循环中生成字符串$previousUsedInFunction
(以检测我们是否有函数引用):
elsif (/\.o\): In function \`([a-zA-Z0-9_.():]*)\'/) {
print ("$_");
$previousUsedInFunction = $1;
}