Skip to content

Commit 778c8e2

Browse files
committed
Fix linking on macOS to only use system dylib
> otool -L ./bindgen/target/scala-native-bindgen ./bindgen/target/scala-native-bindgen: /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11) /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4) /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
1 parent 4492a6b commit 778c8e2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

bindgen/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,18 @@ execute_process(COMMAND ${LLVM_CONFIG_PROGRAM} --system-libs --link-static
4646
include_directories(SYSTEM ${LLVM_INCLUDE_DIR})
4747

4848
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS}")
49-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LINKER_FLAGS} -static")
5049

51-
add_compile_options(-fexceptions -std=c++11 -Wall -Wconversion) # -Werror)
50+
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
51+
# macOS does not guarantee backwards compatible system calls and therefore
52+
# discourages statically linked binaries. Instead add -L/usr/lib before the
53+
# LLVM LDFLAGS to link against the dynamic system libc++ instead of the one
54+
# from LLVM.
55+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/lib ${LLVM_LINKER_FLAGS}")
56+
else()
57+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_LINKER_FLAGS} -static")
58+
endif()
59+
60+
add_compile_options(-Wall -Wconversion)
5261

5362
add_executable(bindgen
5463
Main.cpp

0 commit comments

Comments
 (0)