Hello all!
Writing own example of using Swift/CPP interoperability. Got stacked with this error when building it:
[1/2 3.8/sec] Building CXX object CMakeFiles/UsingSwiftCPPInterop_v1.dir/main.cpp.o
[2/2 3.0/sec] Linking Swift executable UsingSwiftCPPInterop_v1
FAILED: UsingSwiftCPPInterop_v1 CMakeFiles/UsingSwiftCPPInterop_v1.dir/Swift/atestmodule.swift.o
duplicate symbol '_main' in:
../CMakeFiles/UsingSwiftCPPInterop_v1.dir/main.cpp.o
../CMakeFiles/UsingSwiftCPPInterop_v1.dir/Swift/atestmodule.swift.o
ld: 1 duplicate symbols
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
What is missing by me? The code of CMake project published here
My build envieionment: CMake 3.29.3 MacOS 14.7.1
In this project Swift files linked directly to project/target. Should it be separated to library target o there must be some parameters that is telling clang to compile it without main?
Solution found. Somehow it was related to Ninja, but can't say why it's not working with Ninja that is default for Qt environment. When changed to Xcode - everything works fine for me.
There are published by me example that is working with CMake/Xcode compilation under Qt Creator. This example oriented on building Swift modules for MacOS/iOS environment only. If you need to build Swift project for the Linux or Windows follow this example from Apple repository on Github