How does one build a OpenSSL library for Project Catalyst? - ios

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?

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.

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:
I used the same directory in to which I had previously extracted and built openSSL for IOS.
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"),
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.
Execute make clean to clear all the objects from the prior IOS build
Execute make This successfully built openSSL.
In Xcode, under -> General -> "Frameworks, Libraries and Embedded Content" I removed both libcrypto.a and libssl.a this was a critical step
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).
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
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
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.

Related

Xcode - Dynamically Adding 3rd party framework

I have seen a few topics regarding this subject, but as I am not very familiar with xcode and the various ways to include external dependencies, my question is specific to the ZoomSDK.
Zoom provides 2 versions of the SDK, one for simulator and one for device only.
In the integration guide they have you
manually add the framework to the "Embeded Binaries" and "Linked Frameworks and Libraries"
add the bundle to "Build Phases > Copy Bundle Resources"
In Xcode I do not see separate options for "Embeded Binaries" and "Linked Frameworks". I do have one section for "Frameworks, Libraries, and Embeded Content".
I added the framework here, followed the rest of the install directions and zoom is working appropriately.
I have placed the sdk files in /lib and am able to swap the files for the correct version when building/running the app. (Zoom - Simulator, Zoom - Device Only)
Rather than manually moving the files before building, is there a way to store the files in /lib/zoom-device and /lib/zoom-sim and have xcode choose the appropriate folder when building for device vs sim?
This is a react-native project and eventually i would like to create/add a pod. (currently /lib/ is in .gitignore and any other devs need to download the sdk and create the folder manually)
I managed to create a pre-action under edit scheme->build
case ${ARCHS} in
*arm*)
cp -R ${PROJECT_DIR}/lib/MobileRTC/* ${PROJECT_DIR}/lib
;;
*i386*|*x86_64*)
cp -R ${PROJECT_DIR}/lib/MobileRTC-Simulator/* ${PROJECT_DIR}/lib
;;
esac
There are probably better ways to do this but it is working.

dyld: Library not loaded: #rpath/libswiftAVFoundation.dylib Reason: image not found

I'm getting this error upon launch of my app. I am building under Xcode 9.0 (9A235) on MacOS High Sierra 10.13. I also tried building under Xcode 8.3.3 with the same result. The project is generally Objective C, but the framework YouAppi.framework is Swift:
dyld: Library not loaded: #rpath/libswiftAVFoundation.dylib
Referenced from: /private/var/containers/Bundle/Application/7D3E2815-4CA3-4258-AEF6-C0626055A8F2/dingbats.app/Frameworks/YouAppi.framework/YouAppi
Reason: image not found
At first glance, this appears to be a duplicate of this question, but the error is different in that one. In that other question, the Reason is no suitable image found, where mine is image not found.
I've tried the following to resolve:
Remove and re-add the framework
Clean and Option+Clean the project
Delete ~/Library/Developer/Xcode/DerivedData folder
Build Settings -> Always Embed Swift Standard Libraries = Yes
Build Settings -> Strip Swift Symbols = No
Build Settings -> Linking -> Runpath Search Paths --
added #loader_path
added #rpath
added #executable_path/Frameworks
Checked developer and distribution certificates that Trust was set to Use System Defaults
Checked that I have latest WWDR and G2 certificates installed
Checked validity of above-mentioned certificates
Moved YouAppi.framework into Frameworks/ folder. (It was originally in a "Third-Party Frameworks" folder.)
Tried copying libswiftAVFoundation.dylib into my project's Frameworks folder
I haven't moved to a new computer recently.
I have the same result on my iPhone 7+ running iOS 11.0.23 (15A432) as well as an iPad Mini 1 running iOS 9.3.5 (13G36).
Also tried this:
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData
rm -rf ~/Library/Caches/com.apple.dt.Xcode
Ideas?
When including a framework built with Swift in a non-Swift project, the Swift standard libraries need to be copied into the final output. Xcode has a checkbox for this (#4 in the original question), but apparently there's a bug where, in some cases, it doesn't actually happen.
I saw another thread somewhere that said this happens when you have a framework built with Swift, which is built for multiple architectures, such as armv7 and arm64. (See the thread here.)
In any case, the solution is to add them all manually. The files you are looking for are in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos.
What I did was this:
Step 1. Open Terminal and type this, copying the libraries to a new folder, swiftStdLib, in your home directory.
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos
mkdir ~/swiftStdLib
cp libswift*.dylib ~/swiftStdLib
Step 2. Within Xcode, go to General -> Embedded Binaries, and hit the + to add. Click Add Other, then navigate to your home folder/swiftStdLib. Select all and hit enter.
Step 3. Clean and build the project.
Hope this helps someone.
UPDATE FOR XCODE 11:
In Xcode 11.3, the Swift libraries folder has changed to include the major Swift version number. The original question was based on Xcode 9, so this probably changed earlier than Xcode 11.3, but I haven't checked.
The new folder is /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos.
So that makes Step 1, above, this instead:
cd /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos
mkdir ~/swiftStdLib
cp libswift*.dylib ~/swiftStdLib
Before adding frameworks try this:
I deleted derived data in xcode9 - it works for me
refer link below: How to delete contents from derived data
How can I delete derived data in Xcode 9?
Deleting old developer certificates from Keychain Access helped for me.
Just cleaning the project sometimes seems to work for me. I have noticed this happen more frequently when I have a swfit/objc/c++ project combination.
Simple step to follow
Project -> Build Phases -> Embed Frameworks -> +.
It will works for all.. Perfect solution for everyone.
Add library in Link Binary with Libraries &
Add new Copy Files Phrase, Select framework in destination section and import library there.
And Run your code.. Magic.. Enjoy
NOTE:-Please make sure "Copy only when installing" in Copy files is unchecked

how to build DLIB for iOS

I'm trying to build DLIB for an iOS project. Running the cmake results in a libdlib.a and a load of .o files.
When I add the library to an Xcode project I get warning that the library hasn't been built for arm64.
My question is two-part:
How can I build DLIB for iOS (I tried cmake **path_to_source** -DCMAKE_OSX_ARCHITECTURE="arm64" but it caused loads of errors e.g. unknown type name '__uint32_t'; did you mean '__uint128_t')?
What is the purpose of all the .o files that get built when you run cmake? Do I need to include them in an Xcode project?
I finally figured out how to do this:
Requirements
X11 (on a mac you can just open the X11 app and if X11 isn't installed it'll take you to the download).
Xcode
cmake (you can use home-brew for that)
Steps
In terminal make the lib-xx.xx/examples your root
Run:
mkdir build
cd build
cmake -G Xcode ..
cmake --build . --config Release
This will create a folder called dlib_build in which you can find an Xcode project that compiles the library. In the build settings of that Xcode project you can set the build architecture and SDK for any Xcode supported OS you like!
EDIT:
You have to include a lot of custom compiler flags and 3rd party libraries to get dlib to work in a project. Check out the examples.xcproject build settings.
To compliment RASS's answer, I am attaching screenshots showing how to change this to and from an iOS and OSX lib
After opening the project,
Select the project file from the project navigator
Select the dlib target all the way down the bottom
Select 'Build Settings'
Expand 'Base SDK' drop down
Select either iOS or macOS (OSX)
I hope this helps some people out! gl
Rob Sanders and mylogon already show how to build dlib for ios, here is how to use it:
add libdlib.a to project, and add path to library search paths
add all source to include directory(do not add to project), and add path to header search paths.
add accelerate framework, which contains blas symbols.
add preprocessor macros, from building settings, "custom compiler flag"/"other c flags". these macros make sure the header files match the lib.
-DDLIB_JPEG_SUPPORT
-DDLIB_NO_GUI_SUPPORT
-DNDEBUG
-DDLIB_USE_BLAS
-DDLIB_USE_LAPACK

xcodebuild failure clang:error no such file or directory:

Having a problem when building with xcodebuild. My project/app builds fine with the Xcode - gui. It simply isn't finding/building the libcryptopp library which is part of the build process.
The error is:
clang: error: no such file or directory: '/Users/builder/repo/ioskpay/xcode-cryptopp/cryptopp/build/Release-iphoneos/libcryptopp.a'
This particular file should be derived from another project inside the main app - xcodebuild simply isn't correctly pointing at the right file folder which should be:
~/Library/Developer/Xcode/DerivedData
Any ideas?
To fix this, go to your project settings, go to Targets and select your main project target. Then go to Build phases. Under Target dependencies add the static library project.
This way, when you compile the main project, the static library subproject gets compiled before the main project and your static library will be available.
I had the same problem, but for a resource file .m
I opened target -> build phases -> Compile sources
and I found the file the compiler was tell it can't find duplicated: one with strange icon and the other with a normal icon. I simply removed the one with strange icon and it worked. ( I added the file multiple times and I had a merge conflict before that which made something wrong in the project file)
For your case I think you need to remove the lib from target dependencies list and add it again. This may work for you.
In Xcode Version 9.2 (9C40b) this happened when I drug a bunch of files into the project, some of which were duplicate. Rather than simply not adding the duplicates, it added them again and only the name, not the path.
In Target > Build Phases > Compile Sources each of the duplicates showed with no "...in" after them. Each one caused the clang error.
After removing all of the duplicates that Xcode collected, the project compiled and ran.
It makes you use the Project Navigator instead of managing your source files in the Finder. Then the Project Navigator can't replace duplicates like any decent file management system (ahem Finder). 🤨
My xCode info is:
I faced similar errors during xcode building projects (native swift, flutter, react native, native script) in which I got error messages related to clang compilar. Errors like:
clang-4.0: error: no such file or directory: '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/xxxxxxxxxxxxxxx/Index/Data Store'
clang-4.0: error: cannot specify -o when generating multiple output files
others
Despite of errors related with DerivedData for native apps can be fixed by deleting the directory and, eventually, restart xCode and even restart the machine... in this case, you will see that after deleting the directory and start building process again, the error comes back.
Then, is the moment of checking the clang installation by running clang --version. The normal output will be something like:
as you can see the InstalledDir is incorrect for xCode. In my case, some days ago I needed to install Anaconda app (R, Python, etc) and, now, I remember that I had to install some dependencies and one of them was clang and its installation was altered.
To fix this problem (in my case that I will not need anaconda any more): (edited)
1.- Delete anaconda and all its dependencies (I recommend to use App Cleaner).
2.- Re-install xCode
After reinstalling xCode, if you type again clang --version, you'll get this:
More info at: https://github.com/flutter/flutter/issues/32457#issuecomment-496161092
Hopefully, this info helps some else.
Best
Ok so by simply adding the correct -target -configuration and -scheme parameters I got this to run correctly. However due to my running this in Jenkins for autobuild purposes it still doesn't work as I'd like - getting stuck in exactly the same place. It's odd because I have the exact same code being built in another job that isn't having this problem. There is no rhyme or reason for it at this point. I will keep shooting rubber bands at it and update when I have an answer...
Sometimes Xcode performs weird.
You have to find that static library project e.g.. "filename.a" under 'Link Binary With Libraries' in Build Phase and then remove it and add it again.
I had the same problem while I was archiving my target. I removed the library and the build succeeded.
For me it was because I had removed a package or pod. I ran pod install and it fixed it
Look for the missing file in the Xcode project i.e the files may be deleted or miss placed.
add the missing files to the xcode, then everything will work fine.
Run this command :
$ conda deactivate

How to separate the SDK from the Xcode and SDK bundle downloaded from Apple developer portal

I downloaded Xcode 4 and iOS SDK 4.3 bundle from https://developer.apple.com/downloads/index.action#. It's a dmg file and I am wondering if there is a way to find out where the iOS SDK is in the dmg file and copy it down to local disk? Anyone has tried that before?
Yes, I have tried that when I was trying to build an unofficial iOS toolchain on Linux (with success, by the way).
You have to mount the DMG - the best option for that is double-clicking the DMG in Finder or typing
hdiutil attach filename.dmg
to a command line.
When you have mounted the file, you'll see a bunch of directories - I don't remember to the exact path, but there should be a directory named Packages. In there, you'll find a dozen of files with the extension .pkg. Actually, these are XAR archives which contain GZip archives, which in turn contain cpio archives.
After having extracted the ones you feel logical (look for iPhoneOS4.3.sdk.pkg and the compilers [clang, GCC] as well), you will have the essential components of the iOS SDK, namely: the toolchain (containing the clang and GCC compilers and the necessary tools, including an assembler, linker and the GNU debugger, GDB) and the headers, frameworks and libraries (for example, UIKit, Foundation, libSystem, libsqlite3).
From now on, you shall be able to write simple makefiles and compile iOS apps without the need for using Xcode.

Resources