diff --git a/cmake/TaichiCore.cmake b/cmake/TaichiCore.cmake index 3545dc68b0fb2..3e5bbad9043fd 100644 --- a/cmake/TaichiCore.cmake +++ b/cmake/TaichiCore.cmake @@ -8,7 +8,14 @@ option(TI_WITH_CC "Build with the C backend" ON) option(TI_WITH_VULKAN "Build with the Vulkan backend" OFF) option(TI_WITH_DX11 "Build with the DX11 backend" OFF) option(TI_EMSCRIPTENED "Build using emscripten" OFF) -set(_TI_SYMBOL_VISIBILITY default) + +# Force symbols to be 'hidden' by default so nothing is exported from the Taichi +# library including the third-party dependencies. +# As Taichi can be used by external projects, some of the internal dependencies +# such as Vulkan, ImGui, etc. could be in conflict with the dependencies of those +# projects. +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) if(TI_EMSCRIPTENED) set(TI_WITH_LLVM OFF) @@ -225,7 +232,6 @@ endif() # everywhere in python. set(CORE_LIBRARY_NAME taichi_isolated_core) add_library(${CORE_LIBRARY_NAME} OBJECT ${TAICHI_CORE_SOURCE}) -set_target_properties(${CORE_LIBRARY_NAME} PROPERTIES CXX_VISIBILITY_PRESET ${_TI_SYMBOL_VISIBILITY}) if (APPLE) # Ask OS X to minic Linux dynamic linking behavior @@ -390,10 +396,6 @@ if (NOT WIN32) # Linux target_link_libraries(${CORE_LIBRARY_NAME} stdc++fs X11) target_link_libraries(${CORE_LIBRARY_NAME} -static-libgcc -static-libstdc++) - if ((NOT TI_EXPORT_CORE) AND (NOT ${_TI_SYMBOL_VISIBILITY} STREQUAL hidden)) # expose api for CHI IR Builder - message(WARNING "Using linker.map to hide symbols!") - target_link_libraries(${CORE_LIBRARY_NAME} -Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/misc/linker.map) - endif () # Avoid glibc dependencies if (TI_WITH_VULKAN) target_link_libraries(${CORE_LIBRARY_NAME} -Wl,--wrap=log2f) @@ -426,7 +428,6 @@ if(NOT TI_EMSCRIPTENED) add_library(${CORE_WITH_PYBIND_LIBRARY_NAME} SHARED) endif () - set_target_properties(${CORE_WITH_PYBIND_LIBRARY_NAME} PROPERTIES CXX_VISIBILITY_PRESET ${_TI_SYMBOL_VISIBILITY}) # Remove symbols from static libs: https://stackoverflow.com/a/14863432/12003165 if (LINUX) target_link_options(${CORE_WITH_PYBIND_LIBRARY_NAME} PUBLIC -Wl,--exclude-libs=ALL) diff --git a/misc/linker.map b/misc/linker.map deleted file mode 100644 index 8172240c474b8..0000000000000 --- a/misc/linker.map +++ /dev/null @@ -1,13 +0,0 @@ -{ -global: - extern "C++" { - taichi::*; - }; - extern "C" { - Py*; - }; -local: - extern "C" { - *; - }; -};