一些背景故事:我第一次使用Eclipse但是它在解析命名空间std时遇到了麻烦所以我切换到了代码:: blocks,现在我遇到了这个问题。
除了一个错误之外,一切都经过调试就好了:在函数'_start'中:未定义引用'main'(。text + 0x20)。但是,我定义了main(),并没有任何花哨的东西。
code :: blocks version:13.12 编译器:GNU gcc,有g ++跟随c ++ 11
提前致谢。
主要功能
没什么特别之处//: "main.cpp"
#include "bar.h"
#include "foo.h"
#include <iostream>
using namespace std;
int main() {
int num;
bar bar_;
foo foo_;
num = calc(bar_, foo_);
cout << num << endl;
return 0;
}
这是构建日志:
g++ -o bin/Debug/test obj/Debug/bar.o obj/Debug/foo.o
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
答案 0 :(得分:2)
cout << << num << endl;
无效(注意两个重复<<
)。这意味着您的main.cpp
甚至不应该编译。main.o
(main.cpp
的已编译目标文件)。您已关联foo.o
和bar.o
,但您错过了main.o
。您需要如何解决此问题:
main.cpp
main.cpp
以获取目标文件main.o
答案 1 :(得分:0)
嗯..
根据代码块网站,当发生此类错误时,
&#34;请勿查看构建消息标签,查看构建日志标签&#34;
在我的情况下: 它显示了一个链接器中缺少的.so文件。
以下是快速解决方案:
设置&gt;&gt;编译器&gt;&gt;链接器设置选项卡&gt;&gt;添加.so文件的路径(在构建日志中指向)
确保系统中确实存在要添加的.so。
希望这会有所帮助。欢呼。