New to building with Jucer for xcode, newbie question on linking openssl

Hi!

I'm a win developer, and decided to give it a try to build my software on OSX.

On windows I had to download OpenSSL myself, but as I far as I know openssl is part of OSX already  no?

I type openssl in the Terminal and I get "OpenSSL 0.9.8zb"...

What do I have to type into the Introjucer "Header search paths" and "Extra library search paths" to get hold of that OpenSSL installation?

 

Thank you!

Ignore this...

I need to write nothing in Jucer, and just include <openssl/xxx.h> files and it works...

I am having this issue. I already have libssl.a and libcrypto.a but I don’t know how to link them.
I keep getting the below error
Undefined symbols for architecture x86_64 (clang)
Any idea? My code already has all the include <openssl/xxx.h> but it does not help

You probably need to add ssl and crypto to the “External libraries to link” field in the Xcode exporter settings, and the paths to these libraries in the “Extra library search paths” field in each of the exporter’s configuration settings.

1 Like

Thank you @reuk
Really appreciate it.
I think I already have all the links setup.


In openssl-1.1.1l-x86_x64 folder I have include folders which has openssl and inside it all the .h files.
and in openssl-1.1.1l-x86_x64 I have the libcrypto.a and libssl.a files as well.
When I run the application, it gives below error:

Undefined symbols for architecture x86_64:
  "_BIO_ctrl", referenced from:
      boost::asio::ssl::detail::engine::map_error_code(boost::system::error_code&) const in libMyApplication - Debug.a(Connection.o)
  "_BIO_ctrl_pending", referenced from:
      boost::asio::ssl::detail::engine::perform(int (boost::asio::ssl::detail::engine::*)(void*, unsigned long), void*, unsigned long, boost::system::error_code&, unsigned long*) in libMyApplication - Debug.a(Connection.o)
  "_BIO_free", referenced from:
      boost::asio::ssl::detail::engine::~engine() in libMyApplication - Debug.a(Connection.o)
  "_BIO_new_bio_pair", referenced from:
      boost::asio::ssl::detail::engine::engine(ssl_ctx_st*) in libMyApplication - Debug.a(Connection.o)
  "_BIO_read", referenced from:
      boost::asio::ssl::detail::engine::get_output(boost::asio::mutable_buffer const&) in libMyApplication - Debug.a(Connection.o)
  "_BIO_write", referenced from:
      boost::asio::ssl::detail::engine::put_input(boost::asio::const_buffer const&) in libMyApplication - Debug.a(Connection.o)
  "_CONF_modules_unload", referenced from:
      boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in libMyApplication - Debug.a(ListeningBufferManager.o)
      boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in libMyApplication - Debug.a(Connection.o)
  "_ERR_clear_error", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in libMyApplication - Debug.a(Connection.o)
      boost::asio::ssl::detail::engine::perform(int (boost::asio::ssl::detail::engine::*)(void*, unsigned long), void*, unsigned long, boost::system::error_code&, unsigned long*) in libMyApplication - Debug.a(Connection.o)
  "_ERR_get_error", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in libMyApplication - Debug.a(Connection.o)
      boost::asio::ssl::detail::engine::perform(int (boost::asio::ssl::detail::engine::*)(void*, unsigned long), void*, unsigned long, boost::system::error_code&, unsigned long*) in libMyApplication - Debug.a(Connection.o)
      boost::asio::ssl::detail::engine::engine(ssl_ctx_st*) in libMyApplication - Debug.a(Connection.o)
  "_ERR_reason_error_string", referenced from:
      boost::asio::error::detail::ssl_category::message(int) const in libMyApplication - Debug.a(ListeningBufferManager.o)
      boost::asio::error::detail::ssl_category::message(int) const in libMyApplication - Debug.a(Connection.o)
  "_SSL_CTX_ctrl", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in libMyApplication - Debug.a(Connection.o)
  "_SSL_CTX_free", referenced from:
      boost::asio::ssl::context::~context() in libMyApplication - Debug.a(Connection.o)
  "_SSL_CTX_get_default_passwd_cb_userdata", referenced from:
      boost::asio::ssl::context::~context() in libMyApplication - Debug.a(Connection.o)
  "_SSL_CTX_get_ex_data", referenced from:
      boost::asio::ssl::context::~context() in libMyApplication - Debug.a(Connection.o)
  "_SSL_CTX_new", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in libMyApplication - Debug.a(Connection.o)
  "_SSL_CTX_set_default_passwd_cb_userdata", referenced from:
      boost::asio::ssl::context::~context() in libMyApplication - Debug.a(Connection.o)
  "_SSL_CTX_set_ex_data", referenced from:
      boost::asio::ssl::context::~context() in libMyApplication - Debug.a(Connection.o)
  "_SSL_CTX_set_options", referenced from:
      boost::asio::ssl::context::set_options(long, boost::system::error_code&) in libMyApplication - Debug.a(Connection.o)
  "_SSL_accept", referenced from:
      boost::asio::ssl::detail::engine::do_accept(void*, unsigned long) in libMyApplication - Debug.a(Connection.o)
  "_SSL_connect", referenced from:
      boost::asio::ssl::detail::engine::do_connect(void*, unsigned long) in libMyApplication - Debug.a(Connection.o)
  "_SSL_ctrl", referenced from:
      boost::asio::ssl::detail::engine::engine(ssl_ctx_st*) in libMyApplication - Debug.a(Connection.o)
  "_SSL_free", referenced from:
      boost::asio::ssl::detail::engine::~engine() in libMyApplication - Debug.a(Connection.o)
  "_SSL_get_error", referenced from:
      boost::asio::ssl::detail::engine::perform(int (boost::asio::ssl::detail::engine::*)(void*, unsigned long), void*, unsigned long, boost::system::error_code&, unsigned long*) in libMyApplication - Debug.a(Connection.o)
  "_SSL_get_ex_data", referenced from:
      boost::asio::ssl::detail::engine::~engine() in libMyApplication - Debug.a(Connection.o)
  "_SSL_get_shutdown", referenced from:
      boost::asio::ssl::detail::engine::map_error_code(boost::system::error_code&) const in libMyApplication - Debug.a(Connection.o)
  "_SSL_new", referenced from:
      boost::asio::ssl::detail::engine::engine(ssl_ctx_st*) in libMyApplication - Debug.a(Connection.o)
  "_SSL_read", referenced from:
      boost::asio::ssl::detail::engine::do_read(void*, unsigned long) in libMyApplication - Debug.a(Connection.o)
  "_SSL_set_bio", referenced from:
      boost::asio::ssl::detail::engine::engine(ssl_ctx_st*) in libMyApplication - Debug.a(Connection.o)
  "_SSL_set_ex_data", referenced from:
      boost::asio::ssl::detail::engine::~engine() in libMyApplication - Debug.a(Connection.o)
  "_SSL_write", referenced from:
      boost::asio::ssl::detail::engine::do_write(void*, unsigned long) in libMyApplication - Debug.a(Connection.o)
  "_TLS_client_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in libMyApplication - Debug.a(Connection.o)
  "_TLS_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in libMyApplication - Debug.a(Connection.o)
  "_TLS_server_method", referenced from:
      boost::asio::ssl::context::context(boost::asio::ssl::context_base::method) in libMyApplication - Debug.a(Connection.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

And then I add -lcrypto to the Other Linker Flags which remove 10 of the errors above. I have tried many different ways but still cannot get rid of the issue. I tried building with M1 and Intel MacBooks as well and results are the same.
Still don’t know what’s missing.

How does the “Extra libraries to link” field look in the Projucer Xcode exporter settings? It should contain the strings ssl and crypto separated by newlines.

Hi @reuk
I thought in the Extra Library Search Paths I should only provide the path to the folder.
I changed it to

and I got below error:

Can you give me an example of how I should do it? Really appreciate it

I think I made a mistake here by looking at the wrong place.
How can I add these two library in JUCE?


This would say that library not found

The “External libraries to link” field should contain the strings ssl and crypto separated by newlines.

I tried adding ssl and crypto into two separate lines, Also libcrypto.a and libssl.a in two separate lines, also their full absolute path in two separate lines and I still get the error below

ld: library not found for -llibcrypto.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)

My openssl-1.1.1l-x86_x64 folder contains the two .a files (libcrypto.a and libssl.a) and I also added
…/…/openssl-1.1.1l-x86_x64/include to Header Search Path in ProJucer.
What am I missing?

Did you definitely save and reopen the project each time? The error you’re seeing implies that you are supplying the full file name, rather than just “ssl” or “crypto”. If you’re using pre built libraries then you need to ensure that the architecture of the library matches the architecture that you’re building for. You can check this with the “file” command in the terminal, e.g. file /path/to/library. If you’re building on an M1 machine, then x86_64 libraries are unlikely to work.

SOLVED!

Thank you @reuk
This also worked on both M1 and X86.
This is what I did at the end.

  1. Downloaded the OpenSSL (/source/index.html)
  2. Compile both libcrypto.a and libssl.a for both ARM and Intel (if you don’t, it would fail regardless of your machine that you are building)
export MACOSX_DEPLOYMENT_TARGET=10.9
cp -r openssl-1.1.1l openssl-1.1.1l-arm64 
cp -r openssl-1.1.1l openssl-1.1.1l-x86_x64

#Build Intel half
cd openssl-1.1.1l-x86_x64 
./Configure darwin64-x86_64-cc shared
make

#Build ARM half
export MACOSX_DEPLOYMENT_TARGET=10.15
cd ../openssl-1.1.1l-arm64 
./Configure enable-rc5 zlib darwin64-arm64-cc no-asm
make

#Universal binary
mkdir openssl-mac
lipo -create openssl-1.1.1l-arm64/libcrypto.a openssl-1.1.1l-x86_x64/libcrypto.a -output openssl-mac/libcrypto.a

Then go to openssl-mac folder and run the below commands for both libcrypto.a and libssl.a

file libcrypto.a

you should see below

libcrypto.a: Mach-O universal binary with 2 architectures: [x86_64:current ar archive random library] [arm64]
libcrypto.a (for architecture x86_64):	current ar archive random library
libcrypto.a (for architecture arm64):	current ar archive random library
  1. In ProJucer add the path for both libcrypto.a and libssl.a files and also add -lz (will be added to Other Linker Flags in XCode)

  2. add the path of include folder of OpenSSL to the Header Search Paths

When you build it would work. I tried it on two different machines.
I hope it helps others too.

I’ve managed to link the libraries fine and it works so long as I only configure and build for my system (M1 OSX 11). If I try the solution for an M1/Intel compatible version I get an error when building the x86_64 static libraries that says “Object file was built for newer OSX version than being linked” over and over. I’ve been looking for solutions, but none seem to work. Any advice from anybody who has done this?

Which deployment target are you building for and what deployment target does the linker warning report for your library? In the example above the

is the important part to set a correct target before building the x86 slice. Maybe you missed that?

I initially tried this exactly as it was suggested here. I then set the deploy target for 10.11, and when that failed I tried 10.15. Same problem every time.
I’m not sure why it’s not working. It just always says it was built for OSX11 (my OS version) and not the target version.
The arm64 build seems to work fine though

Ok - I have it working now…
As a little update for anybody reading this in the future, I made two mistakes:
1 - I was cloning openssl from github instead of downloading the zipped file directly from openssl.org. Not sure exactly why the github version didn’t play nice, but this solved the errors when building the libraries.
2 - I missed the part about including -lz in the Extra Linker Flags. While this is not part of building the libraries, it is important for working in xcode later.

Thanks all for the help.