C 链接错误 : undefined reference to 'main'

标签 c linker

我已经阅读了关于这个主题的其他答案,不幸的是他们没有帮助我。我试图将几个 c 程序链接在一起,但收到错误响应:

$ gcc -o runexp.o scd.o data_proc.o -lm -fopenmp
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
make: * [runexp] Error 1

我只有一个主要功能,它在 runexp 中。形式是

int main(void) {
    ...; 
    return 0;
}

关于为什么我可能会收到此错误的任何想法?谢谢!

最佳答案

您应该在 -o 选项后提供输出文件名。在您的情况下, runexp.o 被视为输出文件名,而不是输入目标文件,因此您的 main 函数未定义。

关于C 链接错误 : undefined reference to 'main' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15905119/

相关文章:

fgets 在换行前设置空字符后清除输入流

c - C 中的寄存器数组

c - 矩阵乘法时的段错误,c

python - 对 python-dev header 中函数的 undefined reference

c++ - 链接 src/与 CMake 作为库#include'd 与一些 `libname/` 前缀

c++ - 使用 Fortran 编译和链接 C++

c++ - 在 C++ 中使用 STL 的 cURL

c++ - 如何用c++求公因数?

c++ - crt1.o 在 linux x64 上没有这样的文件 c++ 编译错误

c++ - 对 C 宏的 undefined reference ,但在我定义它时会出现重新定义的错误