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

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

我正在编译一个application,它使用适用于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项目中查看链接器行时,它们看起来像:

Xcode linker lines

[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)

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

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为什么不显示其运行的版本?

macos libpng otool
1个回答
0
投票

错误是由于使用的头文件和库之间不匹配。 Mach-O加载命令中指示的库版本不是问题。

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

确保库附带的头是编译器发现的(第一个)头。

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