Getting undefined types with system library module

I am trying to wrap my head around the system modules. I have the following package:

// swift-tools-version:5.4
import PackageDescription

let package = Package(
	name: "SmartRV",
	products: [
		.executable(name: "SmartRV", targets: ["SmartRV"]),
	dependencies: [],
	targets: [
			name: "libgpiod"
		.target(name: "SmartRV", dependencies: ["libgpiod"])

With a module defined as:

module libgpiod [system] {
  header "libgpiod.h"
  link "gpiod"
  export *

However when I try to use a type from the library I am getting:

/home/scott/Projects/SmartRV/Sources/SmartRV/main.swift:4:10: error: cannot find type 'gpiod_chip' in scope

let foo: gpiod_chip

The type is defined in the header for the library.

You are bumping into Opaque Pointers in Swift, as seen recently also in Swift-Linux-Glibc: error: cannot find type 'DIR' in scope - #2 by lukasa. The short version is that gpiod_chip is an "opaque type": C knows it exists, but doesn't know its size or any of its fields. Pointers to this type in Swift manifest as OpaquePointer, not UnsafePointer. You'll need to use OpaquePointer to interact with the type.

Terms of Service

Privacy Policy

Cookie Policy