Visual Studio Does Not Recognize GCC Linker Errors in Makefile Project

We have a visual design makefile project. We already had to present a solution like this in order to recognize compiler errors. I.e. We have implemented a Perl script to parse the output from GCC and convert it into a form that Visual Studio will understand. If we declare:

int succ = thisRandomFunction(userPointer, 1, 1); 

without definition for thisRandomFunction , then we get a linker error:

 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 

But the visual studio does not really recognize this as a mistake. The Visual Studio C ++ console with the same problem has a linker error:

 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 

Using this converter:

 sub parseLinkerError { my $str = $_[0]; my $find = "undefined reference to"; my $replace = "error LNK2019: unresolved external symbol"; $str =~ s/$find/$replace/g; return $str } 

We can convert this:

 1> d:\Git\program/taskqueue.c:94: undefined reference to `thisRandomFunction' 

in that

 1> D:/Git/eV+/program/taskqueue.c(94,1) error LNK2019: unresolved external symbol `thisRandomFunction' 

But this is not enough to deceive the interpreter of the errors of the linker of the visual studio. What are the minimum requirements to view linker errors? Are there any solutions that can work without direct text analysis?

+5
source share
2 answers

According to the documentation ...

The output format should be:

 {filename (line# [, column#]) | toolname} : [any text] {error | warning} code####: localizable string 

Where:

  • {a | b} is the choice of either a or b.
  • [ccc] is an optional string or parameter.

For instance:

 C:\sourcefile.cpp(134) : error C2143: syntax error : missing ';' before '}' LINK : fatal error LNK1104: cannot open file 'somelib.lib' 


Your sample fails because the required colon is missing
 D:/Git/eV+/program/taskqueue.c(94,1) error LNK2019: unresolved external symbol `thisRandomFunction' ^ 
+1
source

So, it seems that adding this line is enough to do this:

 taskqueue.obj : error LNK2019: unresolved external symbol "thisRandomFunction" referenced in function TaskQueueAdd 

As far as I can tell, the error will be detected using the following keys:

 [*].obj : error LNK2019: unresolved external symbol "[*]" referenced in function [*] 

Where [*] can be anything or nothing (it doesn't even need to be an actual function).

So, for <parsing> this script is enough:

 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 the line $previousUsedInFunction generated in the main parsing cycle, using the following if statement (to determine if we had a function reference):

 elsif (/\.o\): In function \`([a-zA-Z0-9_.():]*)\'/) { print ("$_"); $previousUsedInFunction = $1; } 
0
source

Source: https://habr.com/ru/post/1235381/


All Articles