2

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
Stefano Mtangoo
  • 6,017
  • 6
  • 47
  • 93
  • 1
    This isn't your firs SO activity! So please update your question with: respective contents of `CMakeLists.txt`, result of command `brew info zlib`, possibly logs of `cmake -G Xcode .....` – Marek R Jul 03 '20 at 07:49
  • Well I always put minimal useful information to avoid bombarding people trying to help. I will update and try to add as much information as I can but I use CMakeList.txt shipped with wxWidgets. That's true also for libcurl – Stefano Mtangoo Jul 03 '20 at 07:52
  • @MarekR I have updated the question. Let me know if anything else is missing – Stefano Mtangoo Jul 03 '20 at 08:29
  • It looks like because your zlib library is in a directory different than the *standard* directory, it is not found. Your CMake follows a non-traditional method for importing and building an external project which may make it harder to control how this external project *finds* its dependencies. You could use [`ExternalProject_Add`](https://cmake.org/cmake/help/latest/module/ExternalProject.html#command:externalproject_add) or `FetchContent` instead which may make the resolution easier to come by. – Kevin Jul 03 '20 at 13:09
  • "it seems like the libraries search path does not include `/usr/local/opt/zlib/lib` where the library is found." - No, the message ``No rule to make target `/usr/lib/libz.dylib'`` just reflects the fact, that Zlib **has been found** at this path some time ago, or *someone* tells that Zlib is here, so CMake doesn't check that. "Relevant contents of CMakeList.txt" - The only relevant information I found in this `CMakeLists.txt` is how do you configure wxWidgets: `cmake -DCMAKE_BUILD_TYPE=Debug -DwxUSE_EXPAT=builtin -DwxBUILD_PRECOMP=OFF -B `. Is that is all? – Tsyvarev Jul 03 '20 at 13:14
  • When you *configure* wxWidgets (with `cmake`), it should be a message about zlib, like Found ZLIB:. This message should contain the path where zlib has been found. Please, show this message. Alternatively, you may look into `CMakeCache.txt` file located in the build directory (`${CMAKE_CURRENT_BINARY_DIR}/wxWidgets`) and find records like `ZLIB_LIBRARY`, `ZLIB_LIBRARY_RELEASE`, `ZLIB_LIBRARY_DEBUG`. What is value of such records? – Tsyvarev Jul 03 '20 at 13:33
  • @Tsyvarev `is how do you configure wxWidgets:` Yes that is it. Strange enough even compiling libcurl does not work with the same message – Stefano Mtangoo Jul 03 '20 at 13:53
  • The variable is set as follows: `//Path to a library. ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib/libz.dylib ` – Stefano Mtangoo Jul 03 '20 at 13:55
  • Try to remove this line, and run `cmake` from the build directory. Then check, whether the record in `CMakeCache.txt` will be changed. – Tsyvarev Jul 03 '20 at 14:01
  • No It does not change. It is `ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib/libz.dylib` – Stefano Mtangoo Jul 03 '20 at 14:18
  • So, in other words, CMake **recreates** `ZLIB_LIBRARY_RELEASE:FILEPATH=/usr/lib/libz.dylib` line even after you remove it. Have you checked the line `Found ZLIB:` in the `cmake` output? Does this line contain the same path (`/usr/lib/libz.dylib`)? – Tsyvarev Jul 03 '20 at 14:35
  • let me find it, I could not see it – Stefano Mtangoo Jul 03 '20 at 15:29
  • `Found ZLIB: /usr/lib/libz.dylib (found version "1.2.11")` – Stefano Mtangoo Jul 03 '20 at 15:31
  • 1
    Strange thing is,`ls /usr/lib/|grep libz`shows `libz.1.1.3.dylib libz.1.2.11.dylib libz.1.2.5.dylib libz.1.2.8.dylib libz.dylib` The first time I checked I could not see any. So I thought may be the Beta OS does not come with it. So I Installed with brew. Now that it is there am more confused – Stefano Mtangoo Jul 03 '20 at 15:34
  • Be sure to wipe your build dir before re-running cmake? – Richard Barber Jul 04 '20 at 09:38
  • @RichardBarber, I get the same issue. I have tried that many times. It is so strange – Stefano Mtangoo Jul 04 '20 at 15:52
  • Apart from [this](https://stackoverflow.com/a/62734572/18124936), I also needed to restart my computer. – whatever baby Jul 18 '23 at 07:51

2 Answers2

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 )

chenrui
  • 8,910
  • 3
  • 33
  • 43
  • Thanks for pointing that out. I never knew that it exists. But the issue here seems to be CMake or MacOS build system, since both built in and brew installed libz do not work – Stefano Mtangoo Jul 04 '20 at 20:10
  • Definitely worth calling out there (I dont have a DTK machine, so could not help too much :) ) – chenrui Jul 04 '20 at 20:15
1

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

Stefano Mtangoo
  • 6,017
  • 6
  • 47
  • 93