In order to check new features of Xcode9-beta and Swift4 I decided to move one of my test projects which was compiled without problems in Xcode 8.3.3 into separate folder and started experiments…
The project called “RAIDA” was written using Perfect library and had following dependencies:
I have cloned project from Git repository. Of course, initially it did not contain any dependencies. I needed to download them with build tools.
In order to make experiment clean I decided to use Xcode 9 toolchain from the very first operation. To use new toolchain you have to change the setting either from Xcode -> Preferences -> Locations:
or from command line:
$ xcode-select --switch /Applications/Xcode-beta.app/Contents/Developer/
Then you run the program generating Xcode config:
$ swift package generate-xcodeproj
All dependencies were downloaded from repositories and .xcodeproj file was written. Now
$ open RAIDA.xcodeproj started my Xcode 9 with build settings automatically set up.
In Xcode I tried to compile my project as is. I hasn’t chosen “Swift version 4” in Building settings yet. It was “3.2”. But the project has not builded. It failed with following message:
ld: library not found for -lCOpenSSL for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Linker failed. It could not find COpenSSL library which was linked with -l flag.
PerfectNet library depends on COpenSSL which is C project. And it links normally in XCode 8.3.3 without any problem. What happened in XCode 9 that it has stop building?
Actually I spent a day trying different possibilities, playing with linker flags etc. Stackoverflow did not help, People fixed similar issues in different ways but it looked more like “casting” but not engineering solution.
Finally I came to obvious decision — read the XCode release notes. :) Usually we are very lazy to read docs — it is too long and boring. But when you stuck there is no another way. I was very surprised when I found the following in XCode 8.3(!) release notes (remember that in 8.3 I builded project without problems)
I did it in two C libraries — COpenSSL and CHTTPParser and the project builded at last! I believe that you must do the same in every C library you are depending on.
I cant imagine how this could happen that new feature introduced in XCode 8.3 actually began to work in XCode 9. Probably Apple left both old & new building schemes in 8.3
I wiped the sweat from my forehead…
Now it is time to fix these temporary (I believe that PerfectlySoft will fix these in nearest future) problems in my project. Happily swift package now supports “editing mode” for dependencies — when you can can edit dependencies source files and they will not be overwritten by later refetching if it will occur.
swift package edit COpenSSL
swift package edit PerfectHTTPServer
Since PerfectHTTPServer includes C Library CHTTPParser I needed to put it in “edit” mode as a whole.
swift package generate-xcodeproj
Now these packages are in Packages folder of my project and I could add them to git repository in order to fix these important changes.
Hope it will help to somebody!