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

标签 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

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

最佳答案

您可能没有为您的 C 文件定义 main 。当您尝试为每个 C 文件创建单独的可执行文件时,请检查您的各个包含内容。您可能想显示已编译文件的#include。

关于linux - 我正在尝试编写一个 shell 命令来查找并编译所有 C 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16518032/

相关文章:

linux - 文件 Linux Shell 中的列操作

c - 为什么 open/send/sendto/sendmsg 函数中的标志参数是有符号整数而不是无符号整数?

compiler-errors - 从 'double'转换为 'System::TVarRec'模棱两可

java - 第21行显示;预期

c# - 为什么我可以将 1 作为 short 而不是 int 变量 i 传递?

c++ - 是否建议在 bash 脚本中捕获 SIGPIPE?

linux - unix 服务器上的用户配置文件和 bash 配置文件有什么区别

shell - 如何仅将文件中的第三行读入 shell 脚本中的变量

javascript - 未找到从 cli 运行 php 的 grunt-shell 任务

bash - 在 Shell 中以相反顺序重命名文件