脚本以在我的工作目录中的所有.c文件中创建一个静态库
我正在尝试编写一个脚本,该脚本在工作目录中从所有.c
文件中创建静态库调用libwork.a
在目录中:
#!/bin/bash
gcc -c *.c | ar cr libwork.a *.o
但是当我运行脚本时,它仅创建对象文件。 libwork.a
不会创建。我尝试了采购和执行脚本,但它仍然只创建对象文件。
为什么不创建档案?
I am trying to write a script that create a static library call libwork.a
in the working directory from all the .c
files in the directory:
#!/bin/bash
gcc -c *.c | ar cr libwork.a *.o
But as I run my script, it only creates the object files. The libwork.a
does not get created. I tried both sourcing and executing my script but it still only creates object files only.
Why is it not creating the archive?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是卸下该管道,然后简单地将命令一个接一个地运行。
注意“ -e”。这告诉shell如果其中一个命令失败了,那么如果GCC失败,则AR不会执行。
The solution is to remove that pipe and simply run the commands one after the other.
Note the "-e". This tells the shell to abort if one of the commands fails, so if gcc fails ar will not execute.
另外,看看这个:
Also, have a look at this one: