diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -871,6 +871,12 @@ config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) endif() +if (WIN32 AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + # If linking libcxxabi statically into libcxx, skip the dllimport attributes + # on symbols we refer to from libcxxabi. + add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) +endif() + # Setup all common build flags ================================================= function(cxx_add_common_build_flags target) cxx_add_basic_build_flags(${target}) diff --git a/libcxxabi/CMakeLists.txt b/libcxxabi/CMakeLists.txt --- a/libcxxabi/CMakeLists.txt +++ b/libcxxabi/CMakeLists.txt @@ -288,7 +288,14 @@ # Disable DLL annotations on Windows for static builds. if (WIN32 AND LIBCXXABI_ENABLE_STATIC AND NOT LIBCXXABI_ENABLE_SHARED) - add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) + if (LIBCXX_ENABLE_SHARED AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + # Building libcxxabi statically, but intending for it to be statically + # linked into a shared libcxx; keep dllexport enabled within libcxxabi, + # as the symbols will need to be exported from libcxx. + else() + # Regular static build; disable dllexports. + add_definitions(-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS) + endif() endif() add_compile_flags_if_supported(-Werror=return-type)