【发布时间】: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。我切换了顺序,错误消失了(图书馆开始工作)。