我正在尝试编写一个shell命令来查找和编译所有C程序

时间:2013-05-13 08:48:37

标签: linux shell compiler-errors

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

我完全陷入困境,任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:0)

您可能没有为C文件/文件定义主要内容。当您尝试为每个C文件创建单独的可执行文件时,请检查您的个别内容。您可能希望显示已编译文件的#include。