Undefined symbols for C++ types in Release build, fine in Debug build

Hi all,

I have a fairly large C++ library that I am writing Swift bindings for. However, I'm getting the following linker error in release builds specifically. Everything compiles and runs as expected in debug builds.

Ld /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProAI.build/Release/EDOProAI.build/Objects-normal/x86_64/Binary/EDOProAI normal x86_64 (in target 'EDOProAI' from project 'EDOProAI')
    cd /Users/brandon/Developer/EDOProAI
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -Xlinker -reproducible -target x86_64-apple-macos14.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -Os -L/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EagerLinkingTBDs/Release -L/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EagerLinkingTBDs/Release -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release/PackageFrameworks -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release/PackageFrameworks -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release/PackageFrameworks -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release/PackageFrameworks -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release/PackageFrameworks -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release/PackageFrameworks -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release/PackageFrameworks -F/Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Products/Release -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -iframework /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -filelist /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProAI.build/Release/EDOProAI.build/Objects-normal/x86_64/EDOProAI.LinkFileList -Xlinker -rpath -Xlinker @executable_path/../lib -Xlinker -object_path_lto -Xlinker /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProAI.build/Release/EDOProAI.build/Objects-normal/x86_64/EDOProAI_lto.o -Xlinker -debug_variant -fobjc-link-runtime -fprofile-instr-generate -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProAI.build/Release/EDOProAI.build/Objects-normal/x86_64/EDOProAI.swiftmodule -lc++ -Wl,-no_warn_duplicate_libraries -Wl,-no_warn_duplicate_libraries -Wl,-no_warn_duplicate_libraries -Wl,-no_warn_duplicate_libraries -Wl,-no_warn_duplicate_libraries -Wl,-no_warn_duplicate_libraries -Wl,-no_warn_duplicate_libraries -Xlinker -dependency_info -Xlinker /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProAI.build/Release/EDOProAI.build/Objects-normal/x86_64/EDOProAI_dependency_info.dat -o /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProAI.build/Release/EDOProAI.build/Objects-normal/x86_64/Binary/EDOProAI -Xlinker -add_ast_path -Xlinker /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProCore.build/Release/EDOProCore.build/Objects-normal/x86_64/EDOProCore.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/TinyML.build/Release/TinyML.build/Objects-normal/x86_64/TinyML.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/_Differentiation.build/Release/Differentiation.build/Objects-normal/x86_64/Differentiation.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/_Differentiation.build/Release/_Differentiation.build/Objects-normal/x86_64/_Differentiation.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/swift-reflection-mirror.build/Release/ReflectionMirror.build/Objects-normal/x86_64/ReflectionMirror.swiftmodule

ld: Undefined symbols:
  void std::__1::__debug_db_erase_c[abi:v160006]<std::__1::__hash_table<std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::__unordered_map_hasher<unsigned int, std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::hash<unsigned int>, std::__1::equal_to<unsigned int>, true>, std::__1::__unordered_map_equal<unsigned int, std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::equal_to<unsigned int>, std::__1::hash<unsigned int>, true>, std::__1::allocator<std::__1::__hash_value_type<unsigned int, unsigned int>>>>(std::__1::__hash_table<std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::__unordered_map_hasher<unsigned int, std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::hash<unsigned int>, std::__1::equal_to<unsigned int>, true>, std::__1::__unordered_map_equal<unsigned int, std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::equal_to<unsigned int>, std::__1::hash<unsigned int>, true>, std::__1::allocator<std::__1::__hash_value_type<unsigned int, unsigned int>>>*), referenced from:
      /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProAI.build/Release/EDOProAI.build/Objects-normal/x86_64/Decks.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The error above indicates the symbol is referenced in Decks.o, however my Decks.swift file does not use any C++ types.

Strangely, removing the file entirely from the project results in the same error, except with a different object file (which also does not use any C++ types):

ld: Undefined symbols:
  void std::__1::__debug_db_erase_c[abi:v160006]<std::__1::__hash_table<std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::__unordered_map_hasher<unsigned int, std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::hash<unsigned int>, std::__1::equal_to<unsigned int>, true>, std::__1::__unordered_map_equal<unsigned int, std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::equal_to<unsigned int>, std::__1::hash<unsigned int>, true>, std::__1::allocator<std::__1::__hash_value_type<unsigned int, unsigned int>>>>(std::__1::__hash_table<std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::__unordered_map_hasher<unsigned int, std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::hash<unsigned int>, std::__1::equal_to<unsigned int>, true>, std::__1::__unordered_map_equal<unsigned int, std::__1::__hash_value_type<unsigned int, unsigned int>, std::__1::equal_to<unsigned int>, std::__1::hash<unsigned int>, true>, std::__1::allocator<std::__1::__hash_value_type<unsigned int, unsigned int>>>*), referenced from:
      /Users/brandon/Library/Developer/Xcode/DerivedData/EDOProAI-bhygyrwhfezktbgpejfmfyatiyvf/Build/Intermediates.noindex/EDOProAI.build/Release/EDOProAI.build/Objects-normal/x86_64/Array+Extensions.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there a way to ensure the symbols are not stripped during optimization?

1 Like

I've noticed the same issue. I don't have any fixes - just want to add that I'm also looking for a fix.

1 Like