繁体   English   中英

在 macOS 上,为什么 otool -L 不显示应用程序正在运行的 libpng 的版本?

[英]On macOS, why doesn't otool -L show the version of libpng the application is running with?

我正在为 macOS 10.15.4 编译一个使用 CMake 构建系统的应用程序 当我运行构建的应用程序时,我收到一个错误( Application built with libpng-1.5.23 but running with 1.6.37 )通知我编译应用程序的 libpng 版本和它正在使用的版本不匹配当它运行时:

Hostname:sample_data username$ ~/src/github/hoche/splat/build/src/Debug/splat -t ~/src/github/hoche/splat/sample_data/wnju-dt.qth -sdelim _ -L 5 -maxpages 4
.
.
.
Writing Signal Strength map "/Users/username/src/github/hoche/splat/sample_data/wnju-dt.png" (2400x2430 image)... libpng warning: Application built with libpng-1.5.23 but running with 1.6.37
Done!

我已经告诉 CMake 为 Xcode 11.3 生成一个 Xcode 项目文件。 有问题的应用程序使用 libpng。 我告诉 CMake 在我的 CMakeLists.txt 中使用带有以下子句的 libpng:

find_package(PNG REQUIRED)
find_package(JPEG REQUIRED)
find_package(Threads REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
add_executable(splat
    .
    .
    .)
target_link_libraries(splat bz2 ${PNG_LIBRARIES} ${JPEG_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})

我已经通过 MacPorts 安装了 libpng。 当我查看生成的 Xcode 项目中的 linker 行时,它们看起来像:

Xcode 链接器行

otool -L报告:

Hostname:sample_data username$ otool -L ~/src/github/hoche/splat/build/src/Debug/splat 
/Users/username/src/github/hoche/splat/build/src/Debug/splat:
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /opt/local/lib/libpng16.16.dylib (compatibility version 54.0.0, current version 54.0.0)
    /opt/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
    /opt/local/lib/libjpeg.9.dylib (compatibility version 13.0.0, current version 13.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)

如果我检查 linker 行上指示的位置的文件,它们看起来也是正确的:

HOstname:sample_data username$ ls -al /opt/local/lib/libpng*
lrwxr-xr-x  1 root  admin      10 Oct 28  2019 /opt/local/lib/libpng.a -> libpng16.a
lrwxr-xr-x  1 root  admin      14 Oct 28  2019 /opt/local/lib/libpng.dylib -> libpng16.dylib
-rwxr-xr-x  1 root  admin  177352 Oct 28  2019 /opt/local/lib/libpng16.16.dylib
-rw-r--r--  1 root  admin  253120 Oct 28  2019 /opt/local/lib/libpng16.a
lrwxr-xr-x  1 root  admin      17 Oct 28  2019 /opt/local/lib/libpng16.dylib -> libpng16.16.dylib

为什么 libpng 抱怨版本不匹配? 真的是用错版本了吗? 如果是这样,为什么otool -L不显示它运行的版本?

该错误是由于使用的 header 文件与库不匹配造成的。 Mach-O 加载命令中指示的库版本不是问题。

某些对 libpng 的调用要求您将PNG_LIBPNG_VER_STRING作为参数传递。 这有效地将标头中的版本烘焙到调用代码中,libpng 将其与自己的版本进行比较以检查兼容性。

确保库附带的头文件是编译器找到的(第一个)头文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM