Do not force the install libdir (e.g. /opt/local/lib) onto the g-ir-scanner's DYLD_LIBRARY_PATH on macOS. DYLD_LIBRARY_PATH is a forced override, so having the MacPorts libdir on it makes Apple system frameworks (ImageIO) bind their JPEG symbols against MacPorts libJPEG.dylib, which lacks them, e.g. dyld: Symbol not found: __cg_jpeg_resync_to_restart Referenced from: .../ImageIO.framework/.../ImageIOOriginal Expected in: /opt/local/lib/libJPEG.dylib The just-built libraries still need the build dirs on the path; the installed libraries are located via their install names / DYLD_FALLBACK_LIBRARY_PATH. --- cmake/modules/GObjectIntrospection.cmake.orig +++ cmake/modules/GObjectIntrospection.cmake @@ -266,14 +266,34 @@ _loader_library_path_cmake ) - set(_extra_loader_library_path_cmake - ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}/src - ${CMAKE_CURRENT_BINARY_DIR} - ${${gir_extra_libdirs_var}} - ${LIB_INSTALL_DIR} - ${_loader_library_path_cmake} - ) + # On macOS the scanner env sets DYLD_LIBRARY_PATH (a forced override, not a + # fallback). Putting the install libdir (e.g. /opt/local/lib) on it makes + # dyld satisfy Apple framework symbols from MacPorts libraries, which breaks + # with errors such as + # dyld: Symbol not found: __cg_jpeg_resync_to_restart + # Expected in: /opt/local/lib/libJPEG.dylib + # when the scanner subprocess transitively loads ImageIO. The just-built + # libraries still need the build dirs here; the installed ones are found via + # their install names / DYLD_FALLBACK_LIBRARY_PATH, so drop the install + # libdir from the forced path on Apple. + if(APPLE) + set(_extra_loader_library_path_cmake + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}/src + ${CMAKE_CURRENT_BINARY_DIR} + ${${gir_extra_libdirs_var}} + ${_loader_library_path_cmake} + ) + else(APPLE) + set(_extra_loader_library_path_cmake + ${CMAKE_BINARY_DIR} + ${CMAKE_BINARY_DIR}/src + ${CMAKE_CURRENT_BINARY_DIR} + ${${gir_extra_libdirs_var}} + ${LIB_INSTALL_DIR} + ${_loader_library_path_cmake} + ) + endif(APPLE) file(TO_NATIVE_PATH "${_extra_loader_library_path_cmake}"