Mac OS 10.16 Linking Homebrew installed libraries

自闭症网瘾萝莉.ら 提交于 2020-07-23 06:45:44

问题


I have been using homebrew for long time and never faced this strange issue. For some reason I will not explain here am using MacOS 10.16 (Big Sur), a Beta version of latest MacOS and have installed libraries using homebrew. One of those library is zlib. But building with CMake, It cannot find the library. I have tried to build wxWidgets as well as libcurl. Both have failed with similar error:

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

it seems like the libraries search path does not include /usr/local/opt/zlib/lib where the library is found. In another machine running 10.13 High Sierra it works fine.

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"

Relevant contents of 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 Log

Log is so big that cannot be pasted here. See it here: https://pastebin.com/Mk4NrQgX

UPDATE

So I checked out and there is this strange thing happening. When I list with ls, I can see library exists:

ls /usr/lib/|grep libz

libz.1.1.3.dylib
libz.1.2.11.dylib
libz.1.2.5.dylib

But when I try for example to examine the library with 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

I guess the problem lies here, though am yet to crack the code

UPDATE 2

So ran ls -la /usr/lib | grep libz and as you can see it's all linking back to libz.1.dylib but that file does not exist.

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

回答1:


We have a big epic tracker in here for MacOS 10.16/11.0 compatibility check. https://github.com/Homebrew/brew/issues/7857

Feel free to escalate the issue in there (I actually saw the zlib marked as 🥇)




回答2:


It seems some libraries in /usr/lib/are pure garbage. I can confirm zliband libiconvare corrupt, linked to non existing library. No much complain since it is a beta version. So the solution was to install brew version with brew install zlib and then overwrite terminal's current system path with

export PATH=/usr/local/opt/zlib/lib:/usr/local/opt/zlib/include:$PATH



来源:https://stackoverflow.com/questions/62710754/mac-os-10-16-linking-homebrew-installed-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!