问题
gcc -L/root/Desktop - Wall -o prog3.c -pthread -lcopy
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.0: In function '_start': (.text+0x20): undefined reference to 'main'
collect2: error: ld returned 1 exit status
This is my error code. prog3.c
is nowhere to be found, what on earth happened is there any way to get my file back?? The bold is the command I ran and the rest is the resultant console output
回答1:
Your problem is here: -o prog3.c
. gcc
’s -o option is used to tell gcc
which name it should give to the executable it generates. So here, you’re basically asking your compiler to replace your prog3.c
source file by an executable. Sadly your code is gone...
回答2:
Little addendum of your options in such scenario:
It was Git (or any other version control) repository. In such case, you can simply bring it from previous commit
Your editor/IDE has some back-up system. Sometimes I need to bring back a file I've thought was needless. For such case, my favourite text editor should have create already back-up file in appropriate location (e.g.
$XDG_DATA_HOME/vim/backup
in my case).
If none of above, but you still have previously correctly compiled binary file
You can try to decompile, but this process - even if successful - isn't lossless (e.g. code is basically spaghetti).
Had you compiled with
-g
flag, you could possibly retrieve the code from debug info.You can at least de-assemble to Assembly code.
来源:https://stackoverflow.com/questions/47423990/linux-randomly-deleted-my-file-while-compiling-what-do-i-do