【问题标题】:I'm having linking or compilation errors我有链接或编译错误
【发布时间】:2014-03-25 16:55:01
【问题描述】:

我将 Netbeans 用于我的 C++ 项目。我使用 make 编译了我的程序并遇到了这个错误:

collect2: error: ld terminated with signal 11 [Segmentation fault], core dumped
Makefile:4: recipe for target 'barn' failed
make: *** [barn] Error 1

然而,当我在 linux 环境(准确地说是 Ubuntu)中编译它时,它编译得很好。可能出了什么问题?

这是我输入 make -n 时得到的:

g++ -c main.cc
g++ -c Animal.cc
g++ -c Bird.cc
g++ -c Chicken.cc
g++ -c Cat.cc
g++ -c Pig.cc
g++ -o barn main.o Animal.o Bird.o Chicken.o Cat.o Pig.o Random.o

PS 我更喜欢使用 Netbeans

【问题讨论】:

  • 尝试空运行并显示输出:make -n
  • @DavidKernin 编辑了它
  • 哎呀。该段错误是否不止一次发生过?
  • @aschepler 是的,它还没有完全编译
  • 建议尝试将“-Wl,--verbose”传递给 gcc 以调试链接器

标签: c++ linux netbeans compiler-errors linker-errors


【解决方案1】:

链接器中的段错误表明存在错误。如果我遇到这个问题,这就是我会尝试的。

在命令行执行

g++ -o barn main.cc Animal.cc Bird.cc Chicken.cc Cat.cc Pig.cc Random.cc

如果这不起作用,请尝试以下变体:

g++ -o barn main.cc Pig.cc Random.cc Animal.cc Bird.cc Chicken.cc Cat.cc 

顺序应该无关紧要。这正是我会尝试解决这样的神秘肉类问题的那种事情。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-01
    • 2012-07-11
    • 1970-01-01
    • 2014-01-14
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多