Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one build a OpenSSL library for Project Catalyst?

I have to support OpenSSL in my project in building my iPad app for UIKitForMac. Currently, I get these errors.

Building for UIKit for Mac, but the linked library 'libssl.a' was built for freestanding. You may need to restrict the platforms for which this library should be linked in the target editor.

Building for UIKit for Mac, but the linked library 'libcrypto.a' was built for freestanding. You may need to restrict the platforms for which this library should be linked in the target editor.

I was reading about XCFrameworks, but Apple really hasn't put out much information here. Has anyone figured out build scenarios?

like image 306
cvb Avatar asked Jun 05 '19 10:06

cvb


2 Answers

The solution in the comments doesn't work for me. However, I just build to different libs: iOS as I used to and another one for Catalyst by adding the build parameters: -target x86_64-apple-ios13.0-macabi and defining Mac SDK in -isysroot. After that, I just conditionally add each of the libraries for each build version and it works.

like image 83
Shuricksoft Avatar answered Nov 12 '22 05:11

Shuricksoft


Amid mounting frustration following many failed attempts and Google searches, I successfully built openSSL 1.1.1g for Catalyst, compiled my project, linked openSSL and launched the app on my Mac by doing the following:

  1. I used the same directory in to which I had previously extracted and built openSSL for IOS.
  2. Following instructions here, I edited <openSSL directory>/Configurations/10-main.conf. Scrolling down to the "darwin64-x86_64-cc" section, I added a second CFLAGS line:

CFLAGS => add("-target x86_64-apple-ios13.0-macabi"),

  1. In the openSSL directory, execute ./Configure darwin64-x86_64-cc -shared Note that I've seen several other versions of this Configure statement, some with many more options. This command worked for me, but I'm not sure what all the other variations do. You may want to research this further.

  2. Execute make clean to clear all the objects from the prior IOS build

  3. Execute make This successfully built openSSL.

  4. In Xcode, under -> General -> "Frameworks, Libraries and Embedded Content" I removed both libcrypto.a and libssl.a this was a critical step

  5. Switching tabs to Build Phases -> Link Binary With Libraries, verify both archives are removed from this section as well. (It appeared that removing them in step 5 also cleared them in step 6, but I'm not certain).

  6. Back on General -> Frameworks, click the + to add new entries, select "add other" in the lower left corner of the popup window, then provide the path to the newly built libcrypto.a. Repeat for libssl.a

  7. Delete the derived data in a terminal window (I'm not certain this was necessary, but did it out of an abundance of caution):

cd ~/Library/Developer/Xcode
mv DerivedData DerivedData.old
  1. Build the project in Xcode. This successfully completed.

Steps 5-7 turned out to be critical. Even though I moved and/or completely replaced the prior libraries, when I tried to build in Xcode I would get linker errors that I was building for MacOS Catalina but trying to link something built for MacOS x86.

like image 43
Thunk Avatar answered Nov 12 '22 05:11

Thunk