如果版本高于 16 位最大值,Cocoa 框架“当前库版本”会发出 32 位截断警告

问题描述 投票:0回答:2

当设置框架的

DYLIB_CURRENT_VERSION
大于65535时,Xcode会发出警告:

warning build: Truncating -current_version to fit in 32-bit space used by old mach-o format

如果当前版本空间定义为 32 位整数,为什么 Xcode 想要截断大于 16 位最大值的版本?

这是一个错误还是需要调整一些其他设置才能消除此警告?

我使用的Xcode版本是14.0.1。

xcode cocoa cocoa-touch dylib
2个回答
2
投票

因为这 32 位被分割了:

uint32_t version; /* X.Y.Z is encoded in nibbles xxxx.yy.zz */

这是来自不同的加载命令,但 Mach-O 中的所有 32 位版本字段都是这样工作的。这些能代表的最高版本是

65535.255.255

还要注意,从 LLVM 的角度来看,这可能是“旧的”,但 Mach-O 标头中的大多数结构和加载命令仍然使用 32 位版本,没有可用的替代版本,包括“当前”和“兼容”版本动态库。唯一的例外似乎是

LC_SOURCE_VERSION
/
struct source_version_command
,它使用 64 位字段:

uint64_t version; /* A.B.C.D.E packed as a24.b10.c10.d10.e10 */

0
投票

来自

ld
手册页:

 -current_version number
         Specifies the current version number of the library. The current version of the library can be obtained programmatically by the user of the library so it can determine exactly which version of the library it is using.  The format of number is X[.Y[.Z]] where X must be a positive non-zero number less
         than or equal to 65535, and .Y and .Z are optional and if present must be non-negative numbers less than or equal to 255.  If the version number is not specified, it has a value of 0.  This option is also called -dylib_current_version for compatibility.

就我而言,我通过将版本设置为

1.3.268
来触发此警告。

-current_version 1.3.268

由于当我在二进制文件上运行

otool
时,268 大于 255,因此它的上限为
255

$ otool -L build/loader/libfoobar.dylib
build/loader/libfoobar.dylib:
        @rpath/libfoobar.1.dylib (compatibility version 1.0.0, current version 1.3.255)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 2048.1.255)

这就是为什么

ld
警告您这一点。这可能会给您图书馆的用户带来困惑。

© www.soinside.com 2019 - 2024. All rights reserved.