Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift package manager 'cannot find target' error message

I am very new to package manager and can't seem to import a library correctly. I am using the following code:

import PackageDescription

let package = Package(
    name: "MyAppName",
    products: [
        .executable(name: "MyAppName", targets: ["MyAppName"])
    ],
    dependencies: [
        .package(url: "https://github.com/socketio/socket.io-client-swift", .upToNextMinor(from: "13.1.0"))
    ],
    targets: [
        .target(name: "MyAppName", dependencies: ["SocketIO"], path: "./Source Files")
    ]
)

After creating this file and placing it in my project main directory, I open a terminal window and type swift build. The files are fetched however I get the following error message:

could not find target(s): MyAppName; use the 'path' property in the Swift 4 manifest to set a custom target path

I really don't understand the products and targets section of the package file and what I am doing wrong. I just put my app "MyAppName" for the executable and target but don't quite understand if that is correct. Also, not sure the path is correct. I want the libraries to be added to a folder titled Source Files in my main project directory.

like image 409
alionthego Avatar asked Jul 20 '26 00:07

alionthego


1 Answers

Everything in your Package.swift looks fine, you only need to put MyAppName directory with the source files in one of the directories Sources, Source, src, srcs in the top-level directory. So the top-level directory (the one where Package.swift is located) should have the following structure:

TopLevelDirectory |- Package.swift |- Sources |- MyAppName |- MyAppNameSource1.swift |- MyAppNameSource2.swift

Alternatively, you can add the 'path' property to the definition of the target "MyAppName" and to specify where the directory with the sources resides.

Reference: https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageDescriptionV4.md#target-format-reference

like image 156
Vadim Eisenberg Avatar answered Jul 22 '26 14:07

Vadim Eisenberg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!