【问题标题】:List of object files to gcc formatgcc 格式的目标文件列表
【发布时间】:2017-03-26 20:52:16
【问题描述】:

我正在尝试将我的所有文件与我目录中的对象 *.o 扩展名链接。 我尝试使用:

for i in $(find . -name "*.o" -type f); 
    do
        echo $i >> myFiles  
    done

那么我需要:

gcc -o myFile <myFiles

gcc:致命错误:没有输入文件

编译终止。

【问题讨论】:

  • 尝试将其全部扔掉并使用一个命令:gcc -o myfile $(find . -type f -name *.o)

标签: bash gcc


【解决方案1】:

我发现你的方法有几个问题:

findshould not be used in a loop,而是使用-fprint &lt;file&gt;。所以在你的情况下:

find . -name "*.o" -type f -fprintf myfiles

其次,将您的文件重定向到gcc 标准输入不会像您想象的那样工作,因为它使用输入作为代码的see this question。您想要的是将对象列表扩展为参数列表:

cat myfiles | xargs gcc -o myFile

xargs 做得很好。但作为@n.m。提到,您可以通过命令替换一次完成所有操作:

gcc -o myfile $(find . -type f -name *.o -print0)

我建议的唯一区别是使用 -print0,以便 find 在 find 末尾放置 \0 而不是 \n

祝你好运

【讨论】:

    猜你喜欢
    • 2020-11-18
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 2015-05-30
    • 2015-12-16
    • 1970-01-01
    相关资源
    最近更新 更多