linux - "ar"工具允许创建空库

标签 linux compilation binutils unix-ar

如果命令行中指定的某些库不存在,则来自 Binutils 的经典“ar”工具不会失败。 它仅显示消息“ar: <_library_name_>.a: No such file or directory”,但返回代码为零。
这使得有时很难分析构建问题,因为人们会花费大量时间来查找为什么在生成的二进制文件中缺少某些函数。

为什么会有这样的行为?大多数 Linux 用户真的认为正确吗?为什么不至少添加一个失败选项?

ar -V
GNU ar (GNU Binutils for Ubuntu) 2.24

最佳答案

对我有用:

$ ar unknown.a 2>/dev/null || echo 'ko'
ko

$ ar -V
GNU ar (GNU Binutils) 2.28.0.20170506
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.

可能您的 ar 版本太旧。

关于linux - "ar"工具允许创建空库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45504562/

相关文章:

c# - 在 Windows 和 Linux 上部署 C# Windows 窗体应用程序

c - 如何快速动态地加载经常重新生成的C代码?

java - IDEA JetBrains IntelliJ - 'make' 上的编译错误,但使用 Maven 编译时很好,并且 IntelliJ 在类文件中没有报告错误

gnu - 如何理解GNU ld手册中有关链接器脚本的此类示例?

linux - 主机组正在运行的 ansible 剧本 - 没有匹配的主机

c++ - OpenCV 树莓派 printf() 不显示

C++ 模板函数无法将 'std:string' 转换为 'double' 作为返回

c# - 为什么 C# 编译器不捕获 InvalidCastException

linux - 'size' vs 'ls -l' 获取可执行文件的大小

gcc - 将 .o 文件路径添加到 ld 默认值(crtbeginS.o,而不是 .so 文件)