2
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

Barmar
  • 741,623
  • 53
  • 500
  • 612
Midge_Mong
  • 33
  • 2
  • 8

2 Answers2

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...

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
  • ugh, I did not mean to do that. It is all part of a program due tonight for my university, I am a beginner. Guess I better start typing – Midge_Mong Nov 21 '17 at 22:50
  • 1
    Sorry for your work. Barmar is right, you should backup your code! Your editor is probably able to handle that. And don’t forget version-control softwares like Git or SVN. Those allow you to save versions your code and go back to an older version if you messed up. – Ronan Boiteau Nov 21 '17 at 23:05
0

Little addendum of your options in such scenario:

  1. It was Git (or any other version control) repository. In such case, you can simply bring it from previous commit

  2. 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

  1. You can try to decompile, but this process - even if successful - isn't lossless (e.g. code is basically spaghetti).

  2. Had you compiled with -g flag, you could possibly retrieve the code from debug info.

  3. You can at least de-assemble to Assembly code.

Jorengarenar
  • 2,705
  • 5
  • 23
  • 60