我正在尝试编写一个 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/