diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e9dba6ac24..16404b7bef 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -311,6 +311,14 @@ find_package(PythonInterp) include_directories(${CMAKE_BINARY_DIR}/include) +# libleancpp and the stdlib libraries are cyclically dependent. This works by default on macOS, which also doesn't like +# the linker flags necessary on other platforms. +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + set(LEANC_STATIC_LINKER_FLAGS "-lleancpp" "-lInit" "-lStd" "-lLean") +else() + set(LEANC_STATIC_LINKER_FLAGS "-Wl,--start-group" "-lleancpp" "-lInit" "-lStd" "-lLean" "-Wl,--end-group") +endif() + if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") set(LEANC_SHARED_LINKER_FLAGS "${LEANC_SHARED_LINKER_FLAGS} -fPIC") endif() diff --git a/src/bin/leanc.in b/src/bin/leanc.in index ee65efdd85..def749ac5f 100755 --- a/src/bin/leanc.in +++ b/src/bin/leanc.in @@ -16,9 +16,7 @@ bindir=$(dirname $0) cflags=("-I$bindir/../include") ldflags=("-L$bindir/../lib/lean" "-lgmp" @LEANC_EXTRA_FLAGS@) -# static linker flags -# NOTE: libleancpp and libInit are cyclically dependent -ldflags_ext=("-lleancpp" "-lInit" "-lStd" "-lLean" "-lleancpp" "-lInit" "-lStd" "-lLean" "-lStd") +ldflags_ext=(@LEANC_STATIC_LINKER_FLAGS@) for arg in "$@"; do # passed -shared ~> switch to shared linker flags [[ $arg == "-shared" ]] && ldflags_ext=(@LEANC_SHARED_LINKER_FLAGS@)