NOTE: This article relates to using dylibs with iOS simulator only. If you’re building your app for iOS device, you should link against the static libraries. See this link.
Firstly, a couple of thanks: To Doron Adler, who created a fork of a script, of which mine is based on, and who gave some very helpful tips. Also to Jeremy Huddleston from Apple, who also gave some helpful advice.
If you’re like me, you still like to use Indy components for your network connectivity. They cover a wide range of protocols, and they work on Windows, OSX, iOS and Android.
I’m in the process of rebuilding a cross-platform newsreader I started some time ago, and as part of that process, I’m testing functionality on all platforms. For iOS, I prefer to test on simulator first, since I don’t have to have a physical device connected, and I can see how things look on any iOS device.
Somewhere along the line (perhaps when Xcode 7 was released), Apple stopped shipping OpenSSL dylibs that work on iOS simulator. This presents a problem as Indy uses OpenSSL for SSL connections. To add to the woes, the compiler for iOS simulator does not bind statically to .a files (think of them like .DCUs, but for OSX/iOS), so the only choice when using SSL and Indy became to test on the actual device.
Not satisfied with this situation, I set about finding out how to build dylibs for OpenSSL for iOS simulator. To cut a long story short, however many agonising hours later, I managed to come up with relatively painless solution.
Firstly, you should create a working folder somewhere on your Mac, eg /Users/<username>/Source/OpenSSLiOS, where <username> is the username you log into your Mac with.
Into it, copy the script that you can download from here:
OpenSSL iOS Simulator Dylibs Build Script
Download the OpenSSL source from here, or for older versions: here, and put it in the same folder as the script. Expand the OpenSSL .gz file, so now you will have a script file, the .gz file and a folder with the OpenSSL source.
For the modifications that follow, I find Sublime Text is an excellent editor. You can just use TextEdit, if you so choose.
If you’re using a different version of OpenSSL from that which the script is built for, you’ll need to modify the OPENSSL_VERSION= line in the script to match.
NOTE: Some servers have not had their SSL updated (to protect against Logjam attacks <link>), and connecting to them using later versions of OpenSSL may fail. e.g. the SSL on Embarcadero’s news server (this may change after this article is published). In order to successfully connect to these I used version 1.0.2a of OpenSSL. The latest version (1.0.2g at time of writing) may work on other servers.
Next, modify the Makefile.shared file that’s in the root of the folder which contains the OpenSSL source.
The line that needs to be modified looks like this:
[sourcecode language=”bash”] SHAREDFLAGS="$$SHAREDFLAGS -install_name $(INSTALLTOP)/$(LIBDIR)/$$SHLIB$(SHLIB_EXT)"; \[/sourcecode]
Replace $(INSTALLTOP)/$(LIBDIR)/ with @executable_path, so that the line looks like this:
[sourcecode language=”bash”] SHAREDFLAGS="$$SHAREDFLAGS -install_name @executable_path/$$SHLIB$(SHLIB_EXT)"; \[/sourcecode]
The @executable_path value means that the system will expect the dylib to be in the same location as the executable. We’ll see why this is important when deployment is covered.
Next, the script needs to have its properties changed so that it can be executed. Using the Terminal app,
change folder to the one created earlier to put the script in, e.g:
cd /Users/<username>/Documents/OpenSSLiOS
where <username> is the username you log into your Mac with, then use the following command:
chmod +x openssl-build-shared.sh
..and execute the script:
sudo ./openssl-build-shared.sh
This will take about 5-10 minutes depending on your machine. When it has finished successfully, the resulting dylibs will be in the lib/iOS folder, which is off of the folder where the script is located.
If necessary, copy/move these files to a location where they can be included in your Delphi project to be deployed with your app. In my setup, I have a folder shared to a VirtualBox VM that has Delphi 10 Seattle installed, so I can share files between my Mac and the VM.
In your Delphi project, bring up the deployment manager. Click the Add files button
Navigate to the folder containing the dylibs, select both of them and click OK
The remote path (.\) is the same folder as the application, so this does not need to be changed (same as the @executable_path in the makefile, described earlier)
In your code, somewhere before it attempts to make an SSL connection you will need to set the OpenSSL search path for Indy, when compiling for the iOS simulator:
[sourcecode language=”delphi”] IdOpenSSLSetLibPath(TPath.GetDirectoryName(ParamStr(0)));[/sourcecode]
This sets the path to the dylibs as the executable directory.
I hope this has been of some use. It was certainly satisfying for me to finally make this work, and I wanted to share it with others.
Useful post, thanks. Unfortunately many of the image links are broken, so most images are not displayed. Could you fix those, please?
I’m looking into what the problem is, however clicking on where the images should be shows the images as a popup
Good write-up, Dave! 🙂
I’m in the same situation, and checking your script to see if it can help.
In line 121, you check if the *.tar.gz file exists, and if not, proceed to download it. But since expansion of the tar.gz file is skipped, this step seems superfluous.
Or am I missing something?
Yes, it is superfluous, however my version of the script is just slightly modified from the original
Thank you for the clarification!
This doesn’t work in 10.1 Berlin. I have tried A and G, with and without the @executable_path edit (by skipping the Makefile edit and defining absolute lib path instead of adding it to deployment and defining relative lib path). Do you have any insight on this? I am using Indy 10.6.2.5341 also. Thank you.
I’ll have a look at it over the weekend, thanks Bobby
Sorry for the delay, however I’ve done the same process as per my own documentation here and it works ok for me using Delphi 10.1 Berlin
Like your blog but other than looking at the date of any comments I can’t see the blog post date, which is helpful in terms of determining relevance, versions of Delphi etc.
Fixed the display of the date now, thanks! Also thanks for the heads up re: versions of Delphi that the posts apply to; I’ll keep it in mind for future posts
Hi Dave – thanks for this resource… I am trying to follow this for building the libs for Tokyo 10.2.1 and OpenSSL 1.1.0f, but the script fails… Have you been able to successfully build the libraries for this configuration?
I am yet to build with 1.1.0f. I can have a look in a couple of hours. In the meantime, what’s the error message(s), if any?
I have provided the log from Terminal below. I checked the /tmp/openssl-1.1.0f-i386 folder and there is no include directory there. Also – I am trying this on a Mac Mini running macOS Sierra (10.12.6).
Here is the log from Terminal (in case that helps):
—————————————-
OpenSSL version: openssl-1.1.0f
iOS SDK version: 10.3
iOS deployment target: 7.0
OS X deployment target: 10.7
—————————————-
Cleaning up
Using openssl-1.1.0f.tar.gz
Unpacking openssl
Start Building openssl-1.1.0f for i386
Configure
make install
make clean
Done Building openssl-1.1.0f for i386
Start Building openssl-1.1.0f for x86_64
Configure
make install
make clean
Done Building openssl-1.1.0f for x86_64
Copying headers
cp: /tmp/openssl-1.1.0f-i386/include/openssl/*: No such file or directory
Hi
I am using the OpenSSL1.1.0l version. When i ran the script, the include and lib directories are created but there isn’t any dylib files below the lib directory.
Is this for Indy? You won’t be able to use version 1.1.0l of OpenSSL anyway:
https://github.com/IndySockets/Indy/issues/183
Regardless, tomorrow I’ll see if I can make it work for version 1.0.2t (the latest version that Indy supports)
HI Dave
Thanks. I was looking at your script (openssl-build-shared.sh) and it was having problem in compiling
I modified the echo Configure to include a “Mac” to show some debugging.
I created a directory called OpenSSL in Downloads/chris/OpenSSL. Then i when i run your script, it will download the openssl-1.1.0l from the server and extract inside the OpenSSL directory.
When it build, the dylib
—————————————-
OpenSSL version: openssl-1.1.0l
iOS SDK version: 13.0
iOS deployment target: 7.0
OS X deployment target: 10.7
—————————————-
Cleaning up
Using openssl-1.1.0l.tar.gz
Unpacking openssl
Start Building openssl-1.1.0l for i386
Configure Mac
make install
make clean
Done Building openssl-1.1.0l for i386
Start Building openssl-1.1.0l for x86_64
Configure Mac
make install
make clean
Done Building openssl-1.1.0l for x86_64
Copying headers
cp: /tmp/openssl-1.1.0l-i386/include/openssl/*: No such file or directory
The problem is that the headers are never in /tmp/openssl-/include directories.. even it is dylib and many files are being generated in Downloads/chris/OpenSSL/openssl-version directory but not in the /tmp directory.
I am trying to use SSL for Indy socket.
Please advise
regards
chris
hi
I even have the same error as the person before me which is many years ago.
The compilation is done on the current directory of the openssl source and not on the tmp directory.
how can the temp directory has the include files?
Copying headers
cp: /tmp/openssl-1.1.0f-i386/include/openssl/*: No such file or directory
Yes, it looks like I left a couple of lines in that should not be there, including that one.
I expect this may require a bit more “hoop jumping” anyway, because it may require Xcode 10 (maybe even earlier) to be used, since it’s likely to be the last one to have i386 architecture available for iOS simulator SDKs.
Perhaps someone with Xcode 10 (or earlier) can verify whether the dylibs will build successfully. I did manage to find the ones I built when I wrote this article, and have put them here:
https://github.com/DelphiWorlds/KastriFree/tree/master/Lib/OpenSSL/1.0.2g/iOSSimulator
No guarantees that they’ll work 🙂
Hi Dave
I tried to compile the same source on my iMac and Macbook Pro using the same MacOS 10.14.6 and same Xcode 11.0 and both produces different results.
In the iMac, it cannot compile for i386. Seems like it is not supported for i386. It just stopped in the configure command. For the Macbook Pro, i am able to compile until that last part of the “cp” statement.
The dylib files are found in the OpenSSL source directory but you issue a clean command, all the files are removed.
Now, how can i proceed?
what r the files needed for further compilation?
please advise
chris
See my reply from a few minutes before yours 🙂
Hi Dave
Tried your suggestion to use the dylib from Github.
Din work.
I am trying to use FTPS (FTP using SSL) to connect to my FTP server.
Windows no problem
When i tried it on iOS Simulator (ver 10.0), the error is “Error in Connecting: SSL negotiation failed”.
Version 10.0 is still using 32 bit arch.
Soon, this arch will be outdated and need to upgrade to 64 bit.
seems like i have to find a way to make such libraries.
I thought Embarcadero said that these files are found in the system. I wonder what they meant by “found in the system”.
regards
chris