SwiftPM Using a System Library


Please excuse me if this is obvious - but for the life of me I cannot get a system library as a target in a swift executable using the SwiftPM.

Initially I tried the method in the documentation here:

That method involves creating a whole separate package as a git repo then making that a dependency of the main package. Alas I couldn't get that to work and I noticed that that method was deprecated as noted in the compilation output.

So - this time I'm attempting the newer technique as described here:

My package manifest is as so:

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

import PackageDescription

let package = Package(
    name: "libNFCTest",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
    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.
			name: "libnfc", 
			pkgConfig: "libnfc",
			providers: [
					.brew(["libnfc"]) ]),
            name: "libNFCTest",
            dependencies: ["libnfc"]),
            name: "libNFCTestTests",
            dependencies: ["libNFCTest"]),

and my module.modulemap file is as so:

module cairo 
    umbrella header "libnfc.h"
    link "libnfc"

I have libnfc installed via Brew, but upon attempts to compile I get:

Compile Swift Module 'libNFCTest' (1 sources)

**/Users/diggory/Code/OpenSource/libNFCTest/Sources/libNFCTest/main.swift:1:8:** **error:** **no such module 'libnfc'**

import libnfc


**error:** terminated(1):

What am I getting wrong?

Right -- I'm an idiot - I've just seen the copy/paste error that I made.

Actually - even with the corrected typo, I now get the same compilation error that I got with the previous technique.

The compiler appears to recognise the functions defined in the header file referenced (libnfc.h), but not the types defined in another header which is #included in that header (libnfc-types.h).

**main.swift:3:18:** **error:** **use of undeclared type 'nfc_context'**

var nfcContext : nfc_context
Terms of Service

Privacy Policy

Cookie Policy