unixgcccommand-line

Does changing the order of compiling with GCC in unix delete files?


So I just messed up real bad.. I'm hoping someone can tell me I didn't just ruin everything I did for the last 4 weeks with this simple typo..

I kept making changes to my C program and would recompile to test the changes using this in terminal:

gcc -o server server.c

Due to programming for the past 5 hours straight for the most part.. I accidentally typed this the last time I tried compiling:

gcc -o server.c server

I got some long message and realized my mistake.. tried recompiling using the first way I listed.. And it says "no such file server.c"

I typed "ls" and sure enough.. my program isn't there.

Please tell me everything I did hasn't vanished? :((


Solution

  • Unfortunately, you told the compiler to read your executable, and write its output to your source file. The file is gone. If you are on a Windows system, perhaps it could be undeleted with something like Norton Utilities. If not, you're probably out of luck.

    Next time, consider using a Makefile to contain the compiler commands, so you can just type "make" to build your program. Other strategies include keeping the file open in a single editor session the whole time you're working, and using a source control system like git or subversion (which would let you back up to previous versions of the file, as well.)