Error using swift build - Package Manager

Hello everybody!

I searched the forum, but found no evidence of a solution to my problem.
I have an Xcode project that builds a Swift framework. Everything works fine. Now I want to make this framework available for Linux too and use the Swift Package Manager. My Package.swift looks like this:

import PackageDescription
let package = Package(
    name: "MyLib",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "MyLib"
            targets: ["MyLib"]),
        ],
    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 which this package depends on.
        .target(
            name: "MyLib",
            dependencies: [],
            path: "./MyLib/CommonSource"),
        .testTarget(
            name: "MyLibTests",
            dependencies: ["MyLib"],
            path: "./MyLib/CommonTests")
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ]
)

Unfortunately, the following error is displayed when building using swift build:

error: argument 'targets' must precede argument 'dependencies'  targets: [

If I rearrange the arguments, the following error message comes up:

error: incorrect argument label in call (have 'name:products:targets:dependencies:', expected 'name:pkgConfig:targets:dependencies:')

Does anyone have a solution?
Swift-Version:

Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2) Target: x86_64-apple-darwin17.7.0

Best regards!

PS: Using the same Package.swift and folder structure in Linux (Debian Stretch), the library builds fine.

Do you have tools version comment in your manifest file? If no, run this:

$ swift package tools-version --set-current
2 Likes

Oh, also the position of dependencies section is wrong. It should come after products and before targets.

That was it! Thanks. Now it builds fine.