I spent a few more hours hitting my head against the issue. I still cannot find a way to link using a custom library search path. For now, my Makefile copies my .a file to /usr/local/lib. I consider this a defeat, even though I can now build pure-C libraries and call them from Swift.
% cat Makefile PKGNAME="CTestPackage" all: cc -c $(PKGNAME).c -o $(PKGNAME).o ar rvs $(PKGNAME).a $(PKGNAME).o sudo cp $(PKGNAME).a /usr/local/lib/lib$(PKGNAME).a git init ; git add . ; git commit -m "Commit" ; git tag 1.0.0 clean: rm -rf .git sudo rm /usr/local/lib/lib$(PKGNAME).a rm *~ *.[ao]
I’ve tried sneaking flags into the “link” entry for module maps (including -L and -v) and got nowhere. I’ve tried walking through the documentation, trying to find any kind of tweaks around this, but still nothing.
If my intent were to create a re-usable package that’s applicable to multiple projects, /usr/local/lib would be the way to go. Right now, I just want a way to build stuff in C to work around early Swift language limitations on Linux. This means I’m cluttering up a meaningful folder with non-meaningful libraries of temporary code.
3 Comments
I found this page to be helpful. Has a corresponding Makefile too: http://dev.iachieved.it/iachievedit/more-swift-on-linux/
To help people who stumble on this post, this looks to be possible in current swift package manager version via:
swift build -Xlinker -L/usr/local/lib
It’s now 8 months later, and I too found that to succeed with the first
swift build
on https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md
| have to do this:
swift build -Xlinker -L/usr/local/lib
I used
brew install jpeglib
BTW, I also had to add
#include
to /usr/local/include/jpeglib.h