2

I'm trying to build ORB_SLAM2 on macOS 11.4 with clang 12 and OpenCV4 and have run into this error:

make[2]: *** No rule to make target `/usr/lib/libz.dylib', needed by `../lib/libORB_SLAM2.dylib'. Stop.

This file does not exist on my Mac and I cannot add this symlink due to macOS's SIP. The correct path should be /usr/local/opt/zlib/lib/libz.dylib

How can I fix this /usr/lib/libz.dylib reference?

Here is my branch with my macOS build changes.

I've tried to fix the problem by:

  • Inspecting each of the project's direct dependencies with otool -L and rebuilt from source where necessary (such as OpenCV) to make sure /usr/lib/libz.dylib is not referenced (fix suggested here)
  • Using CMake's FindZLIB.cmake module in the ORB_SLAM2 CMakeLists.txt to ensure the correct ZLIB is found

Below is the output showing ZLIB is found but still no luck:

-- Found ZLIB: /usr/local/opt/zlib/lib/libz.dylib (found version "1.2.11")
collenjones
  • 510
  • 5
  • 19
  • You need to find out **origin** of wrong path `/usr/lib/libz.dylib`. It could be not cleared cache (`CMakeCache.txt`), it could be some utility which gives wrong path, it could be hardcode. Unless you find the origin, you will unlikely be able to fix a problem. – Tsyvarev Jun 06 '21 at 19:29
  • It's definitely not a cache, I've cleared entire `build` directory. Do you have any tips on how I can quickly find where this path is coming from? I did a scan of `/usr/local/opt` dylibs and there are many references still to the wrong `libz` path. Hoping there is a faster way to fix this than rebuilding all of those libs from source. – collenjones Jun 06 '21 at 19:32
  • I would start with the verbose build (`make VERBOSE=1`) and check out the exact command line for the linker contains the wrong path. – Tsyvarev Jun 06 '21 at 19:33
  • Searching the source and or build dir for text files containing `libz.dylib` may narrow down the search... It should occur in some file used by make as dependency... – fabian Jun 06 '21 at 20:35
  • Maybe just remove that reference and use `-lz` to link the zlib dylib already installed in macOS. – Mark Adler Jun 06 '21 at 22:22
  • Your branch builds fine for me. Unless you're doing something explicit, you should be picking up `libz.tbd` a la `-- Found ZLIB: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/libz.tbd (found version "1.2.11")` – nega Jun 06 '21 at 22:55
  • Thanks for the answers, everyone. I was dumb and CMake was pulling in Pangolin from another project of mine. Adding Pangolin to this project solved the issue. – collenjones Jun 07 '21 at 01:46

1 Answers1

1

Solved: I checked the CMakeFiles/Makefile.cmake and it showed me that the Pangolin library I was using was actually one from another project of mine. Building Pangolin in this project solved the issue.

collenjones
  • 510
  • 5
  • 19