且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

对共享库main的未定义引用

更新时间:2022-04-11 22:53:26

您的链接命令缺少 -shared 标志,该标志是链接共享库所必需的.

Your link command is missing -shared flag, which is required to link a shared library.

不幸的是,您的构建系统没有显示失败的链接命令.

Unfortunately, your build system did not print the link command that failed.

像这样简单地重现错误:

The error is trivially reproduced like so:

echo "int foo() { return 0; }" | gcc -xc -

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
...
/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