Skip to content

Missing symbols when linking with -enable-cxx-interop importing std::vector #58468

@darknoon

Description

@darknoon

Describe the bug

When embedding an std::vector in the type from C++, binaries and test targets do not link correctly when linking against the Swift module that depends on the C++ target.

Simple code:

from header


#include <vector>

struct Color {
    simd_float4 repr;
};

using ColorArray = std::vector<Color>;

class Life {
public:
    __attribute__((swift_name("life")))
    int my_life = 0;
    
    ColorArray colors = ColorArray();
    
    Life();

    ~Life();

};

To Reproduce
Steps to reproduce the behavior:

  1. Clone repo https://github.com/darknoon/swiftcxxtest at the relevant hash
  2. Build
    ...

Expected behavior
Compiles without errors

Screenshots
If applicable, add screenshots to help explain your problem.

Undefined symbols for architecture arm64:
  "std::__1::vector<Color, std::__1::allocator<Color> >::vector(std::__1::vector<Color, std::__1::allocator<Color> > const&)", referenced from:
      initializeWithCopy value witness for __C.std.__1.__CxxTemplateInstNSt3__16vectorI5ColorNS_9allocatorIS1_EEEE in MyLib.o
      Life::Life(Life const&) in MyLib.o
  "std::__1::__libcpp_deallocate(void*, unsigned long, unsigned long)", referenced from:
      std::__1::allocator<Color>::deallocate(Color*, unsigned long) in MyLib.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Screen Shot 2022-04-27 at 6 00 37 PM

Environment (please complete the following information):

  • macOS 12.3.1 (21E258)
  • Xcode Version 13.3 (13E113)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.c++ interopFeature: Interoperability with C++

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions