Quantcast
Channel: Package Manager - Swift Forums
Viewing all articles
Browse latest Browse all 167

SwiftPM can't build executable with dependencies on Linux/Win platforms

$
0
0

Hello,

I try to build cross platform package for iOS/OSX/Lin/Win platforms based on C++ & Swift code.
So I made simplest package with C++ library target, Swift executable, dependent on C++ library and C++ executable, dependent on C++ library.
And I can successfully build it with OSX. But when I try to build package with Linux or Windows swift it produce same error for cxxMain target:

main.cpp:3:10: fatal error: module 'cxxLibrary' is needed but has not been provided, and implicit use of module files is disabled
#include "cxxLibrary.h"

At the same time MyCli executable target (Swift) built and run well on all platforms. So it looks like something wrong with module search on Linux/Windows platforms for C++ targets.

Need help....

Package file is:

// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyCli",
    platforms: [.macOS("13.3"), .iOS("14.0")],
    products: [
        .library(
            name: "cxxLibrary",
            targets: ["cxxLibrary"]),
        .executable(
            name: "MyCli",
            targets: ["MyCli"]),
        .executable(
            name: "cxxMain",
            targets: ["cxxMain"])
    ],
    targets: [
        .target(
            name: "cxxLibrary",
            cxxSettings: [
              //.headerSearchPath("."),
              .unsafeFlags(["-std=c++2b"])
            ]),
        .executableTarget(
            name: "MyCli",
            dependencies: ["cxxLibrary"],
            swiftSettings: [.interoperabilityMode(.Cxx)]),
        .executableTarget(
            name: "cxxMain",
            dependencies: ["cxxLibrary"],
            cxxSettings: [
              //.headerSearchPath("."),
              .unsafeFlags(["-std=c++2b"])
            ]),
    ]
)

cxxLibrary files:

// cxxLibrary.h
#pragma once
void sayHello();

// cxxLibrary.cpp
#include "cxxLibrary.h"
#include <cstdio>

void sayHello() {
    printf("Hello from c++\n");
}

MyCli files:

// main.swift
import cxxLibrary

print("Hello, world 1!")
sayHello()

cxxMain files:

// main.cpp
#include <print>
#include "cxxLibrary.h" // Error is here !!!!!!!!!!!!!!!!

int main(int argc, char *argv[]) {
    std::print("cxxMain\n");
    sayHello();
}

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 167

Trending Articles