我使用自制软件已经很长时间了,从来没有遇到过这个奇怪的问题。由于某些原因,我在这里不解释使用的是MacOS 10.16(Big Sur),这是最新MacOS的Beta版,并且已经使用自制软件安装了库。这些库之一是zlib
。但是用CMake进行构建时,找不到库。我试图建立wxWidgets以及libcurl。两者都失败,并显示类似错误:
-- make[2]: *** No rule to make target `/usr/lib/libz.dylib', needed by `lib/libwx_baseu-3.1.dylib'. Stop.
make[1]: *** [libs/base/CMakeFiles/wxbase.dir/all] Error 2
make: *** [all] Error 2
似乎库搜索路径不包含找到库的/usr/local/opt/zlib/lib
。在另一台运行10.13 High Sierra的计算机上,它可以正常工作。
brew info zlib
zlib: stable 1.2.11 (bottled) [keg-only]
General-purpose lossless data-compression library
https://zlib.net/
/usr/local/Cellar/zlib/1.2.11 (12 files, 376.4KB)
Poured from bottle on 2020-07-02 at 11:34:14
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/zlib.rb
==> Caveats
zlib is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
For compilers to find zlib you may need to set:
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
For pkg-config to find zlib you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"
CMakeList.txt的相关内容
cmake_minimum_required(VERSION 2.8.11)
# Project name
project(MyApp)
# This setting is useful for providing JSON file used by CodeLite for code completion
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(CONFIGURATION_NAME "MacOSXDebug")
set(CL_WORKSPACE_DIRECTORY ..)
# Set default locations
set(CL_OUTPUT_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/${CL_WORKSPACE_DIRECTORY}/cmake-build-${CONFIGURATION_NAME}/output)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CL_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CL_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CL_OUTPUT_DIRECTORY})
set(PROJECT_Studio_PATH "${CMAKE_CURRENT_LIST_DIR}")
set(WORKSPACE_PATH "${CMAKE_CURRENT_LIST_DIR}/..")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#Build wxWidgets first
message("Building wxWidgets Libraries")
execute_process(COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/wxWidgets)
execute_process(COMMAND git submodule update --init
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/../dependencies/wxWidgets
)
find_program(CMAKE_EXE cmake HINTS "/usr/local/bin/")
message("CMake executable at: ${CMAKE_EXE}")
execute_process(
COMMAND ${CMAKE_EXE} -DCMAKE_BUILD_TYPE=Debug -DwxUSE_EXPAT=builtin -DwxBUILD_PRECOMP=OFF ${CMAKE_SOURCE_DIR}/../dependencies/wxWidgets -B ${CMAKE_CURRENT_BINARY_DIR}/wxWidgets
ERROR_VARIABLE WX_BUILD_ERROR
COMMAND_ECHO STDOUT
)
message(STATUS ${WX_BUILD_OUTPUT})
message(STATUS ${WX_BUILD_ERROR})
execute_process(
COMMAND make -j4 #VERBOSE=1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/wxWidgets
ERROR_VARIABLE WX_BUILD_ERROR
COMMAND_ECHO STDOUT
)
message(STATUS ${WX_BUILD_OUTPUT})
message(STATUS ${WX_BUILD_ERROR})
#Setup wxWidgets
set(ENV{PATH} "${CMAKE_CURRENT_BINARY_DIR}/wxWidgets:$ENV{PATH}")
set(WXWIN ${CMAKE_CURRENT_BINARY_DIR}/wxWidgets)
set(CMAKE_MACOSX_RPATH TRUE)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
CMake日志
日志太大,无法在此处粘贴。在这里查看:https://pastebin.com/Mk4NrQgX
更新
所以我检查了一下,发现这件事很奇怪。当我用ls列出时,我可以看到库存在:
ls /usr/lib/|grep libz
libz.1.1.3.dylib
libz.1.2.11.dylib
libz.1.2.5.dylib
但是,当我尝试使用otool
检查库时
otool -L /usr/lib/libz.dylib
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/objdump: error: '/usr/lib/libz.dylib': No such file or directory
我想问题出在这里,尽管还没有破解代码
更新2
如此运行ls -la /usr/lib | grep libz
,您可以看到它全部都链接回libz.1.dylib
,但该文件不存在。
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.1.1.3.dylib -> libz.1.dylib
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.1.2.11.dylib -> libz.1.dylib
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.1.2.5.dylib -> libz.1.dylib
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.1.2.8.dylib -> libz.1.dylib
lrwxr-xr-x 1 root wheel 12 Jan 1 2020 libz.dylib -> libz.1.dylib
答案 0 :(得分:1)
我们在这里有一个大型的史诗般的追踪器,用于MacOS 10.16 / 11.0兼容性检查。 https://github.com/Homebrew/brew/issues/7857
随时可以在那里升级问题(我实际上看到zlib标记为?)
答案 1 :(得分:1)
/usr/lib/
中的某些库似乎是纯垃圾。我可以确认zlib
和libiconv
已损坏,已链接到不存在的库。由于它是测试版,因此没有太多抱怨。因此解决方案是使用brew install zlib
安装brew版本,然后使用
export PATH=/usr/local/opt/zlib/lib:/usr/local/opt/zlib/include:$PATH