Building Blender on Mac OS X 10.11 - Linking error due to old system zlib

When running make on Mac OS X 10.11 it fails with this error:

  "_inflateValidate", referenced from:
      _png_inflate_claim in libpng.a(pngrutil.c.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is a result of libpng requiring a newer version of zlib (at least zlib-1.2.9 as far as I know) than provided by the system.

Solution:

  • install brew
  • brew install zlib
  • brew info zlib
  • Copy the two lines after For compilers to find zlib you may need to set:
    e.g.
  export LDFLAGS="-L/usr/local/opt/zlib/lib"
  export CPPFLAGS="-I/usr/local/opt/zlib/include"
  • run both export commands in the terminal
  • Yay, Blender should now build

NOTE:
This build is not portable, since it requires zlib to be in the directory specified in LDFLAGS.

@akitula I guess this could be fixed somehow, but it’s probably not worth the work.

I have a patch for that. Since “make deps” builds zlib anyway, the trick is link against that instead of the system provided zlib. This may actually be safer, since our libpng is built with those newer zlib headers.

1 Like

Since this forum won’t let me attach patch or text files, here’s the patch inlined. Note that this relies on zlib being in the lib folder with the other dependencies. This is not included in the binaries from svn, I build them myself using make deps.

From 299bfcd3b538e1908bbf968a3a2e39c13cf34e50 Mon Sep 17 00:00:00 2001
From: Stefan Werner <[email protected]>
Date: Mon, 22 Oct 2018 08:33:45 +0200
Subject: [PATCH] Setting Mac build to use custom zlib instead of system zlib.

---
 build_files/build_environment/cmake/harvest.cmake | 2 ++
 build_files/cmake/platform/platform_apple.cmake   | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/build_files/build_environment/cmake/harvest.cmake b/build_files/build_environment/cmake/harvest.cmake
index 0e98780e3f0..d0d3197c99c 100644
--- a/build_files/build_environment/cmake/harvest.cmake
+++ b/build_files/build_environment/cmake/harvest.cmake
@@ -199,5 +199,7 @@ harvest(x264/lib ffmpeg/lib "*.a")
 harvest(xvidcore/lib ffmpeg/lib "*.a")
 harvest(embree/include embree/include "*.h")
 harvest(embree/lib embree/lib "*.a")
+harvest(zlib/include zlib/include "*.h")
+harvest(zlib/lib zlib/lib "*.a")
 
 endif()
diff --git a/build_files/cmake/platform/platform_apple.cmake b/build_files/cmake/platform/platform_apple.cmake
index 4047a8f134d..8c190f8af63 100644
--- a/build_files/cmake/platform/platform_apple.cmake
+++ b/build_files/cmake/platform/platform_apple.cmake
@@ -128,8 +128,9 @@ endif()
 set(PNG_LIBRARIES png)
 set(JPEG_LIBRARIES jpeg)
 
-set(ZLIB /usr)
+set(ZLIB ${LIBDIR}/zlib)
 set(ZLIB_INCLUDE_DIRS "${ZLIB}/include")
+set(ZLIB_LIBPATH ${ZLIB}/lib)
 set(ZLIB_LIBRARIES z bz2)
 
 set(FREETYPE ${LIBDIR}/freetype)
-- 
2.19.0
1 Like