簡體   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