From 8a8d1b0cea0df4237e2be2dd4d8d9aa5dbc4a2b5 Mon Sep 17 00:00:00 2001 From: shahasad <43590019+shahasad@users.noreply.github.com> Date: Wed, 6 Feb 2019 15:27:37 -0800 Subject: [PATCH] Fix MacOS shared library build (#447) * try removing the --version-script * remove --no-undefined flag * remove the -rpath linker flag * remove the -rpath linker flag, including the -Wl * remove the --whole-archive flags * added -all_load -noall_load flags in place of --whole-archive and --no-whole-archive * spell correct all-load * set the MacOS specific cmake configs with if(APPLE) condition * added --build_shared_lib to mac CI --- cmake/onnxruntime.cmake | 17 +++++++++++++---- .../github/azure-pipelines/mac-ci-pipeline.yml | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake index 31579d9375..6ad7f009c2 100644 --- a/cmake/onnxruntime.cmake +++ b/cmake/onnxruntime.cmake @@ -32,15 +32,24 @@ target_include_directories(onnxruntime PRIVATE ${ONNXRUNTIME_ROOT}) onnxruntime_add_include_to_target(onnxruntime gsl) if(UNIX) - set(BEGIN_WHOLE_ARCHIVE -Xlinker --whole-archive) - set(END_WHOLE_ARCHIVE -Xlinker --no-whole-archive) - set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker --version-script=${SYMBOL_FILE} -Xlinker --no-undefined") + if (APPLE) + set(BEGIN_WHOLE_ARCHIVE -Xlinker -all_load) + set(END_WHOLE_ARCHIVE -Xlinker -noall_load) + else() + set(BEGIN_WHOLE_ARCHIVE -Xlinker --whole-archive) + set(END_WHOLE_ARCHIVE -Xlinker --no-whole-archive) + set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker --version-script=${SYMBOL_FILE} -Xlinker --no-undefined") + endif() else() set(ONNXRUNTIME_SO_LINK_FLAG "-DEF:${SYMBOL_FILE}") endif() if (NOT WIN32) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") + if (APPLE) + set_target_properties(onnxruntime PROPERTIES INSTALL_RPATH "@loader_path") + else() + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") + endif() endif() #The BEGIN_WHOLE_ARCHIVE/END_WHOLE_ARCHIVE part should contain the implementations of all the C API functions diff --git a/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml index 55b6f4234a..c81271622b 100644 --- a/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml @@ -5,7 +5,7 @@ jobs: steps: - script: | sudo xcode-select --switch /Applications/Xcode_10.app/Contents/Developer - ./build.sh --skip_submodule_sync --parallel + ./build.sh --skip_submodule_sync --parallel --build_shared_lib displayName: 'Command Line Script' - template: templates/clean-agent-build-directory-step.yml \ No newline at end of file