re: Calling Swift from Go VIEW POST


Hello, I tried to reproduce what is described in this blog post.

I'm using swift 5 and go1.12.4

When I try to compile, I got:

▶ go build .
ld: library not found for -lmac
clang: error: linker command failed with exit code 1 (use -v to see invocation)

(mac is replacing the go_swift name)

Here is the preamble:

#cgo CFLAGS: -I./include
#cgo LDFLAGS: -lmac
#include <stdlib.h>
#include "include/mac.h"
import "C"

I did swift build before.
Look like it doesn't find the lib.

Here is what swift build is generating:

murlok/internal/mac  swift ✗                                                                                  23m ⚑ ◒
▶ ls -l .build/debug/
total 32
drwxr-x---   4 maxence  staff    128 Apr 20 10:05 ModuleCache
drwxr-x---   3 maxence  staff     96 Apr 20 10:05 index
drwxr-xr-x  10 maxence  staff    320 Apr 20 10:05
-rw-r--r--   1 maxence  staff    372 Apr 20 10:05 mac.swiftdoc
-rw-r--r--   1 maxence  staff  10844 Apr 20 10:05 mac.swiftmodule
drwxr-x---   3 maxence  staff     96 Apr 20 10:05 macPackageTests.product

Do you have an idea of what the problem could be?


I had a similar error in a different project, after upgrading MacOS (and Swift to Swift 5?). Solved it by deleting .build directory, and re-building the project.
Did you try the example project ?

code of conduct - report abuse