C:找不到主目录,但是在那儿|编译错误 [英] C: main not found, but it's there | Compilation error
问题描述
当我像下面给出的那样编译两个.c文件时,我得到了一个非常奇怪的错误.
When I compile two .c files like given below I get a really weird error.
在终端上编译的代码
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
...
我做了一些阅读,解决的方法似乎是添加一个主文件.但是我知道,在编译之前,我的main.c文件中包含int main(). 这是编译之前所有内容的列表:
I did a bit of reading and the solution seems to be to add a main file. But I know for a fact I had the main.c file with the int main() in it before compiling. Here's the list of everything before compiling:
> ls
errors.txt main.c main.c~ matrix.c matrix.c~ matrix.h matrix.h~
编译后,这是所有内容的列表:
After compilation this is the list of everything present:
> ls
errors.txt main.c~ matrix.c matrix.c~ matrix.h matrix.h~
由于某种原因,每次编译时main.c都会被删除.奇怪的是,直到几分钟前,一切都运转良好.有人可以帮忙吗?
For some reason my main.c is getting deleted everytime I compile. What's weird is everything was working perfectly till a couple of minutes ago. Can someone help?
推荐答案
gcc -I. -o main.c matrix.c -lblas -lgfortran
-o main.c
告诉编译器将其编译后的输出写入文件main.c,这可能不是您想要的.您可能想要:
the -o main.c
tells the compiler to write its compiled output into the file main.c, which is probably not what you want. You probably want:
gcc -I. -o progname main.c matrix.c -lblas -lgfortran
这篇关于C:找不到主目录,但是在那儿|编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!