Visual Studio 无法识别 Makefile 项目中的 GCC 链接器错误 [英] Visual Studio doesn't recognize GCC linker Errors in Makefile Project
问题描述
我们有一个交叉编译的 Visual Studio Makefile 项目.我们已经不得不引入一个 与此类似的解决方案 让它识别编译器错误.IE.我们引入了一个 Perl 脚本来解析 GCC 的输出并将其转换为 Visual Studio 可以理解的形式.如果我们声明:
We have a cross compiled visual studio Makefile project. We have already had to introduce a solution similar to this to get it to recognize compiler errors. Ie. We have introduced 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);
如果没有对 thisRandomFunction
的定义,我们就会得到链接器错误:
with no definition for thisRandomFunction
then we will get the 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
但 Visual Studio 实际上并未将其识别为错误.具有相同问题的 Visual Studio C++ 控制台程序出现链接器错误:
But visual studio doesn't actually recognize this as an error. A Visual Studio C++ console program with the same problem has the 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
通过使用这个转换器:
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 链接器错误解释器.看到链接器错误的最低要求是什么?是否有任何解决方案可以在不直接解析文本的情况下工作?
But this isnt enough to trick the visual studio linker error interpreter. What are the minimum requirements for it to see a linker error? Are there any solutions that can work without directly parsing the text?
推荐答案
根据 文档...
输出格式应为:
{filename (line# [, column#]) | toolname} :
[any text] {error | warning} code####: localizable string
地点:
- {a |b} 是 a 或 b 的选择.
- [ccc] 是一个可选的字符串或参数.
例如:
C:\sourcefile.cpp(134) : error C2143: syntax error : missing ';' before '}'
LINK : fatal error LNK1104: cannot open file 'somelib.lib'
<小时>您的示例失败,因为它缺少必需的冒号
Your sample fails because it's missing a required colon
D:/Git/eV+/program/taskqueue.c(94,1) error LNK2019: unresolved external symbol `thisRandomFunction'
^
这篇关于Visual Studio 无法识别 Makefile 项目中的 GCC 链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!