I have an existing c++ library that I have been using in a swiftUI app by using Obj-C wrappers. Now I want to wrap that library in a Swift Package but when I follow the Getting Started Document I get an error that says "Library Product should not contain executable targets".
So I have a Project set up with a folder structure that looks like this;
There are numerous hpp and cpp files in subfolders under source. The target path and publicheaderspath seem to be recursive by default. Is that correct? This part is working.
My Package file looks like this;
// swift-tools-version: 5.7 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "MyInterOpSPM", products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "MyC++Library", targets: ["MyC++Library"]), .library( name: "MyLib4Swift", targets: ["MyLib4Swift"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "MyC++Library", dependencies: , path: "./Sources/cppLibrary_submodule/ALibraryProj/c++/myLibrary/src", publicHeadersPath: ".", cxxSettings: [ .headerSearchPath(".") ] ), .executableTarget(name: "MyLib4Swift", dependencies: ["MyC++Library"], path: "./Sources/MyLib4Swift", sources: ["main.swift"], swiftSettings: [.unsafeFlags([ "-I", "./cppLibrary_submodule/ALibraryProj/c++/myLibrary/src", "-enable-experimental-cxx-interop", ])] ) ], cxxLanguageStandard: CXXLanguageStandard(rawValue: "gnu++17") )
This follows the example in Getting Started. This gives me the error
library product 'MyLib4Swift' should not contain executable targets (it has 'MyLib4Swift')
I've tried changing the .executableTarget to .target and .library to .executable but then I get
'MyLib4Swift' was identified as an executable target given the presence of a 'main.swift' file. Starting with tools version 5.4.0 executable targets should be declared as 'executableTarget()'
When I try to import anything from here into main.swift, Xcode doesn't "see" anything. If, however, a testTarget is attached to this, Xcode will offer the test target as an import option.
What am I doing wrong? Thanks in advance!