I have noticed that an erroneous compilation and linkage command results in the deletion of one of my C source files.
Assume I have 2 source files and a header file:
cc -std=c99 -Wall -Werror -pedantic -o test1.c test2.c
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
Your command is outputting to
test1.c, the command fails and therefore effectively deletes the file.
cc -std=c99 -Wall -Werror -pedantic -o output test1.c test2.c ^ the output flag
I've modified your command to output the program to
[Edited due to further question in comments]
To the question of why
cc deletes the file: I ran
strace -f cc -o test1.c test2.c to find out more about what it was doing. At some point in the output of strace you see this line:
[pid XXXXX] unlink("test1.c") = 0
unlink will delete a file, read more at
man 3 unlink.
I believe the reason
cc deletes the file is
cc thinks it is creator of the file, and therefore is trying to clean up after itself.