c++ - C: main 没有找到,但它在那里 |编译错误

标签 c++ c compilation terminal makefile

当我像下面给出的那样编译两个 .c 文件时,我得到了一个非常奇怪的错误。

终端编译代码

  gcc -I. -o main.c matrix.c -lblas -lgfortran

错误:

  /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
  /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
  /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
  /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
  /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
  /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
  /usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
  ...

我做了一些阅读,解决方案似乎是添加一个主文件。但我知道在编译之前我有一个带有 int main() 的 main.c 文件。 这是编译前的所有内容的列表:

  > ls
  errors.txt  main.c  main.c~  matrix.c  matrix.c~  matrix.h  matrix.h~

编译后这是所有存在的列表:

  > ls
  errors.txt  main.c~  matrix.c  matrix.c~  matrix.h  matrix.h~

出于某种原因,每次编译时我的 main.c 都会被删除。奇怪的是,直到几分钟前一切都运行良好。有人可以帮忙吗?

最佳答案

gcc -I. -o main.c matrix.c -lblas -lgfortran

-o main.c 告诉编译器将其编译输出写入文件 main.c,这可能不是您想要的。你可能想要:

gcc -I. -o progname main.c matrix.c -lblas -lgfortran

关于c++ - C: main 没有找到,但它在那里 |编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26623029/

相关文章:

c++ - OpenGL 顶点从侧面被剪切

java - 从 C/C++ 执行交互式 CLI 应用程序

Java在命令行中编译并运行包含2个类的程序

c++ - 如何在不使用++ 或 + 或其他算术运算符的情况下将两个数字相加

java - 我的 java 解释器出了什么问题?

gcc - 我是否正确使用了 libtool?

c++ - 迭代无符号整数的所有值的最漂亮方法

c++ - 读写 QGraphicsScene 到二进制文件

c++ - 根节点以上内容的 Qt xml 文件问题

c - 如何从 C 中的链表构建霍夫曼树?