Swift package manager, linker flags, and dependencies

This switch for security reasons is discussed I believe in the Catalina Release Notes, and in some of the notes in the Relocated Items folder that was created when I installed Catalina. Those items included all the modifications I made at root level and other directories in under root that were going to be made read-only during the installation (for example, I used to use Fink as a package installer, and I had the default /sw that I had to move to another directory, I choose /opt, which is on the Read/Write root partition).

Also, /usr/local/include and /usr/local/lib are not in the SDK directories, they are in the actual /usr/local directory. If you use clang/swiftc, and (optionally) ld, everything should work as you would expect. I'm not an SPM user, so I really can't comment on what search paths it is providing to compilers and linkers. I just know when I use clang and swiftc from the command line, everything works as I would expect from all the Unixes and related operating systems I've programmed on over the years.

Actually, if SPM is changing the syslibroot, as I understand it, /usr/local is assumed to be located in <syslibroot>/usr. If it is being set on macOS to the SDK and related platform /usr directories, there is no /usr/local in those directories, which is why you have to specify /usr/local/lib as a command line setting. Whether that is a bug depends on the SPM core team developers. There may be reasons because of cross-platform compatibility that they went this route.

For clarity, I filed this as SR-12909

Thanks, Cory!

As a point of reference, this issue is a problem for a SSH wrapper package: jakeheis/Shout. See their issue on the subject. Anyone trying to use their package in another project is running into this issue, and it is a big pain in the rear to deal with it. So, yes, I'd call it a bug, and one that seriously interferes with the plug-and-play concept of SPM.

1 Like

So, an update. Actually, two updates.

First, the good news. Last summer, I was eventually able to get things more or less working and compiling inside XCode by creating a .pc file and installing it and the system library (foma) in /usr/local.

At least I'm fairly certain that's where things were at. I just upgraded to macOS 11 Big Sur, and now I have new problems. I also switched from fink to MacPorts, and installed various tools (including pkg-config) in /opt/local. This may or may not be relevant.

I first installed foma in /opt/foma, and tried compiling my code in XCode 12.4. That failed. The error message made me think that SPM inside XCode couldn't find foma.

I recompiled foma and this time installed it in /usr/local. When I compiled in XCode I got a somewhat different error, but it still wouldn't compile.

However, with foma now in /usr/local and foma's pc file in /usr/local/lib/pkgconfig, compiling my code now succeeds if I run swift build at the Terminal instead of having XCode do the build.