diff --git a/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt b/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt index 5f0d7e939cb..e4365d80b61 100644 --- a/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt +++ b/kotlin-native/shared/src/main/kotlin/org/jetbrains/kotlin/konan/target/ClangArgs.kt @@ -50,7 +50,6 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con add(listOf("--gcc-toolchain=${configurables.absoluteGccToolchain}")) } if (configurables is AppleConfigurables) { - add(listOf("-stdlib=libc++")) val osVersionMin = when (target) { // Here we workaround Clang 8 limitation: macOS major version should be 10. // So we compile runtime with version 10.16 and then override version in BitcodeCompiler. @@ -157,10 +156,28 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con val hostCompilerArgsForJni = listOf("", HostManager.jniHostPlatformIncludeDir).map { "-I$jdkDir/include/$it" }.toTypedArray() - val clangArgs = (commonClangArgs + specificClangArgs).toTypedArray() + /** + * Clang args for Objectice-C and plain C compilation. + */ + val clangArgs: Array = (commonClangArgs + specificClangArgs).toTypedArray() + + /** + * Clang args for C++ compilation. + */ + val clangXXArgs: Array = clangArgs + when (configurables) { + is AppleConfigurables -> arrayOf( + "-stdlib=libc++", + // Starting from Xcode 12.5, platform SDKs contain C++ stdlib. + // It results in two c++ stdlib in search path (one from LLVM, another from SDK). + // We workaround this problem by explicitly specifying path to stdlib. + // TODO: Revise after LLVM update. + "-nostdinc++", "-isystem", "$absoluteLlvmHome/include/c++/v1" + ) + else -> emptyArray() + } val clangArgsForKonanSources = - clangArgs + clangArgsSpecificForKonanSources + clangXXArgs + clangArgsSpecificForKonanSources val targetLibclangArgs: List = // libclang works not exactly the same way as the clang binary and @@ -173,7 +190,7 @@ class ClangArgs(private val configurables: Configurables) : Configurables by con = listOf("${absoluteLlvmHome}/bin/clang") + clangArgs private val targetClangXXCmd - = listOf("${absoluteLlvmHome}/bin/clang++") + clangArgs + = listOf("${absoluteLlvmHome}/bin/clang++") + clangXXArgs private val targetArCmd = listOf("${absoluteLlvmHome}/bin/llvm-ar")