Visual studio 2015 VisualStudio没有';无法识别Makefile项目中的GCC链接器错误

Visual studio 2015 VisualStudio没有';无法识别Makefile项目中的GCC链接器错误,visual-studio-2015,Visual Studio 2015,我们有一个交叉编译的VisualStudioMakefile项目。我们已经引入了一种方法来让它识别编译器错误。我们引入了一个Perl脚本来解析GCC的输出,并将其转换为Visual studio可以理解的形式。如果我们声明: int succ = thisRandomFunction(userPointer, 1, 1); 如果没有此随机函数的定义,我们将得到链接器错误: 1> ./program.a(taskqueue.o): In function `TaskQueueAdd':

我们有一个交叉编译的VisualStudioMakefile项目。我们已经引入了一种方法来让它识别编译器错误。我们引入了一个Perl脚本来解析GCC的输出,并将其转换为Visual studio可以理解的形式。如果我们声明:

int succ = thisRandomFunction(userPointer, 1, 1);
如果没有
此随机函数的定义,我们将得到链接器错误:

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
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
但是VisualStudio实际上并不认为这是一个错误。VisualStudioC++控制台程序中存在相同的问题:链接错误:

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
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'

但这还不足以欺骗VisualStudio链接器错误解释器查看链接器错误的最低要求是什么?是否有任何解决方案可以在不直接解析文本的情况下工作?

因此添加这一行似乎就足够了:

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语句在主解析循环中生成字符串
$previousedInFunction
(以检测是否有函数内引用):

根据

输出的格式应为:

{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'

您的示例失败,因为缺少必需的冒号

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

总而言之,在阅读了代码项目的链接后,这是一个好问题(请原谅我以前的怪癖)。你应该让这一点更加突出,用一个简短的摘要来解释,以便为你的问题得到一个简洁的答案。对不起,我自己没有。您是否尝试添加从“/”到“\”的斜杠转换$str=~s/\/\\/@JimBlack是的,我们确实转换了“\”。调整question@Mithaldu评论中不能有垂直空格,可以使用
shift-enter
进行编辑,这可能会使您更轻松。对于给定的示例,这只是为了显示VS链接器错误和GCC链接器错误之间的区别。VS one是一个简单的例子,GCC one来自我试图编译的实际项目。我实际尝试转换的后面的示例都来自同一个项目。@Mithaldu至于尝试,我们尝试了更多的转换。这就是为什么问题的关键是,it部门看到链接器错误的最低要求是什么?这是简单的,明确的,以及在这个网站范围内。我希望答案中有一个代码示例,但我没有在问题中发布它,因为我知道它离题了。谢谢你的建议。谢谢,我在构建perl脚本时没有找到这个文档。这突出了脚本的几个问题。