【问题标题】:On macOS, why doesn't otool -L show the version of libpng the application is running with?在 macOS 上,为什么 otool -L 不显示应用程序正在运行的 libpng 的版本?
【发布时间】:2020-04-30 23:16:17
【问题描述】:

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

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 不显示它运行的版本?

【问题讨论】:

  • 只是一个猜测,但我怀疑错误是由于使用的头文件和库之间的不匹配造成的。我不认为 Mach-O 加载命令中指示的库版本是问题所在。确保库附带的头文件是编译器找到的(第一个)头文件。
  • @Ken Thomases - 你完全正确。包含参数按此顺序出现,-I/Library/Frameworks/UnixImageIO.framework/Headers -I/opt/local/include。我切换了顺序,错误消失了(图书馆开始工作)。

标签: macos libpng otool


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    • 2020-05-06
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 2010-11-03
    • 2018-06-27
    相关资源
    最近更新 更多