简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM