Undefined third-party library symbols when building dylib on MacOS

The following command generates a Makefile on linux that properly builds a .so library:

# Shared library
            mb_cheb.c mb_delaun.c mb_intersectgrid.c mb_readwritegrd.c 
            mb_surface.c mb_track.c mb_truecont.c mb_zgrid.c)

However the same command generates a Makefile on MacOS that results in many undefined symbol errors, for symbols defined in third-party libraries. What are the proper commands that prevent this problem?

What are the exact errors?

If your library requires external (third-part) libraries to link, there should probably be a target_link_libraries(mbauxShared ...) command somewhere to link the libraries in.

The issue - and what looks to be a good solution - is described here.

I use the following linker option on macOS when I know that the symbols will be satisfied at runtime:

-undefined dynamic_lookup

This makes it possible in my project to not link against a specific version of the Python dll, since it is the Python dll loading my library anyway.

This flag depends on whether or not you are using Linux style linking:


To make this macOS specific:

"-undefined dynamic_lookup -flat_namespace")