Problem when compiling example Swift on C++ interop code (5.10)

I've tried out this example code on Linux. My (modified) cpp code is here:

#include "Greeter-Swift.h"

void cPlusPlusCallsSwift() {
  Greeter::printWelcomeMessage("Theo");
}

The command for generating headers is basically this command

My clang command:

!clang++ test.cpp -o test.o /path/to/swift/usr/lib/swift/linux/libswiftCore.so

And these are the errors:

/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
/usr/bin/ld: /tmp/test-430dc9.o: in function `Greeter::printWelcomeMessage(swift::String const&)':
test.cpp:(.text._ZN7Greeter19printWelcomeMessageERKN5swift6StringE[_ZN7Greeter19printWelcomeMessageERKN5swift6StringE]+0x66): undefined reference to `$s7Greeter19printWelcomeMessageyySSF'
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

What did I do wrong here? Are there any additional linker flags?

The C++ Interop test suite has many examples of building small executables to test various features. I suggest you take a look at those to see how to do it, if you don't want to use SwiftPM.

This error says that a function with signature Greeter.printWelcomeMessage(Swift.String) -> () can't be found by the linker. This looks like a Swift function that is declared in the Swift library that you're using from C++.

I suspect you might need to link against the Swift library explicitly. You're already linking against the Swift standard library (libswiftCore.so), which is correct, you probably just need to pass the path to one more binary to Clang.