Installing OpenSSL library for Xcode

29,031

Solution 1

OK, how to build and install it....

It might be easier to use a pre-built version of OpenSSL for iOS. You can find one at this Github account. The OpenSSL from that Github are multi-arch. They have ARMv7, ARMv7s, ARM64, and i386. That means they work with devices and simulators.

Download either OpenSSL 1.0.1e or 1.0.1f. Install it in a location like /usr/local/ssl/ios.

Then, add the headers to your Xcode project. They are located in /usr/local/ssl/ios/include:

enter image description here

Finally, add the multi-arch libs (libcrypto.a and libssl.a) to your Xcode project. They are located in /usr/local/ssl/ios/lib:

enter image description here

Solution 2

You need to add the library as a Framework. See this question: how to add an existing framework in Xcode 5.

Its OK to add the OpenSSL libraries under Frameworks. Its how things are done under Apple/Xcode.

I use the Absolute Path like in the image below because Crypto++, OpenSSL, etc are installed in /usr/local. The image below is a screen capture I have handy of Crypto++, and not OpenSSL's libcrypto.a or libssl.a. But the same applies to all libraries.

enter image description here

Share:
29,031
Marko Zadravec
Author by

Marko Zadravec

Updated on July 09, 2022

Comments

  • Marko Zadravec
    Marko Zadravec almost 2 years

    I have installed OpenSSL in xcode for receipt validation, but it doesn't work.

    I download openssl.xcodeproj and openssl-1.0.1f. I extract openssl-1.0.1f and add openssl.xcodeproj to my project.

    files in finder inserted openssl.xcodeproj

    I edit the Header Search Path to :

     /Users/marko/Documents/Razvoj/BIView\ Mobile\ New\ Version/openssl/include/openssl
    

    I added libcrypto.a in Target Dependencies under Build Phases

    and added libcrypto.a in Link Binary With Libraries

    as was described in http://atastypixel.com/blog/easy-inclusion-of-openssl-into-iphone-app-projects/.

    But when I build project it stops with error :

    clang: error: no such file or directory: '/Users/ .... -bmgslnakszsfovecplbzoslykrxo/Build/Products/Debug-iphoneos/libcrypto.a'
    

    Why ?

  • Marko Zadravec
    Marko Zadravec over 10 years
    My problem is that I have openSll.xcodeproj, and openSLL.tar.gz. If I have openSll.framework I would know what to do.
  • jww
    jww over 10 years
    I don't know what openSll.xcodeproj is. openssl-1.0.N.tar.gz is the source code. Is that what you have? If so, you need to unpack, build, and install it.
  • Marko Zadravec
    Marko Zadravec over 10 years
    OK, how to build and install it. I am new at this stuff and I will be really thankfull if you could help me.
  • jww
    jww over 10 years
    See Compilation and Installation on the OpenSSL wiki. There's also a bunch of INSTALL.<platform> readme's in the root of the source code. The 5 second fly-by: ./config; make all; sudo make install. You'll then find it in /usr/local/ssl.
  • Marko Zadravec
    Marko Zadravec over 10 years
    in terminal in navigate to file where openssl-1.0.N.tar.gz is located and write your script. It says make: *** [links] Error 1 making all in crypto... /bin/sh: /Applications/Xcode: No such file or directory make: *** [build_crypto] Error 1 Password: and I dont know whitch password I should write.
  • jww
    jww over 10 years
    You have to cross-compile OpenSSL for iOS after setting your environment (my bad, I forgot to mention it). See the answer below.
  • Marko Zadravec
    Marko Zadravec over 10 years
    in /usr/local/ I have maps : bin, etc, include, lib, man, Qt, sbin, share, textlive. Do you mean to create new file named ssl, but then libcrypto.a and libssl.a would not be there.
  • jww
    jww over 10 years
    Do a mkdir -p /usr/local/ssl/ios. Then you will have it.
  • Marko Zadravec
    Marko Zadravec over 10 years
    mkdir: /usr/local/ssl/ios: Permission denied
  • Marko Zadravec
    Marko Zadravec over 10 years
    I would be more than happy if You could show me how to make .a or .framework from .tar.gz because after that I have another lib te extract (asn1c.tar.gz). :D But it this field (and terminal in general) I don't have much experience so be patient and go slow. I really appreciate your time.
  • jww
    jww over 10 years
    See the various scripts provided with the iOS tarball. That's what I use to build them. build-all.sh calls the other scripts in turn for a particular platform. The other scripts set the environment and then invoke config, make, etc. Your mileage may vary for asn1c.tar.gz.
  • jww
    jww over 10 years
    "... permission denied... " - sudo mkdir -p /usr/local/ssl/ios.
  • Marko Zadravec
    Marko Zadravec over 10 years
    I try build-all-for-ios.sh but it gives me : **************************************** sed: Configure: No such file or directory sed: Makefile.org: No such file or directory sed: Makefile.org: No such file or directory sed: Makefile.org: No such file or directory **************************************** iPhoneSimulator, -i386 CONFIG_OPTIONS=no-asm no-shared --openssldir=/usr/local/ssl/ios build-all-for-ios.sh: line 42: ./config: No such file or directory make: *** No rule to make target clean'. Stop. cp: ./libcrypto.a: No such file or directory . make:***No rule to make target clean.Stop.`
  • Marko Zadravec
    Marko Zadravec over 10 years
    In the middle is more but I couldn't paste all of it
  • jww
    jww over 10 years
    You should ask another question since this is different from your original question.
  • Marko Zadravec
    Marko Zadravec over 10 years
    I posted new question pleas look and answer
  • Vipulk617
    Vipulk617 over 8 years
    I am using openssl in swift , but getting error . Please suggest it , How to configured openssl with swift.
  • Vipulk617
    Vipulk617 over 8 years
    I want to use openssl in swift , but getting error . Please suggest it , How to configured openssl with swift.
  • Nick
    Nick about 6 years
    In recent versions of Xcode, putting the location in User Search Path results in errors about using angled brackets instead of quotes for the filenames in #include statements. Do what the answer says, but put the location in Header Search Paths instead.