我正在尝试编写一个shell命令来查找和编译所有C程序
find . -type f -name '*.c' -exec sh -c 'gcc {} -o $(dirname {})/$(basename {} .c)' \;
这就是我现在拥有的,它实际上确实编译了所有C文件,但它也返回了这些错误。
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
我完全被困住了,任何帮助将不胜感激。
最佳答案
您可能没有为C文件定义main。在尝试为每个C文件创建单独的可执行文件时,请检查您的个人包含文件。您可能希望显示已编译文件的#include。
关于linux - 我正在尝试编写一个shell命令来查找和编译所有C程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16518032/