How to add OpenSSL to an Xcode project - xcode

I am trying to port an application to mac OSX. It uses openssl. I am new to xcode and mac development. Do I need to compile and install openssl myself, or is there some equivalent of an openssl-devel package available as part of the OS or with homebrew or some such?

Download source from openssl source
.
Extract compressed file into directory of your choice.
.
Open command line and go to that directory and type something similar to ./configure darwin64-x86_64-cc
.
Then type make depend
.
Then make install
.
Go to your Xcode project build settings. Under Header Search Paths add /usr/local/ssl/include and library search paths /usr/local/ssl/lib (or whatever install paths you chose in the configure step)
.
Still in build settings go to Linking and under other linker flags put -lssl -lcrypto
You should be good to go now.

You will need to compile and link it yourself, and your app needs to ship it. If the license of your app and OpenSSL's license are compatible, you may use static linking. Otherwise you will need to dynamically link it.
There are a few documents describing the process and build scripts that you can find with Google searches. For iOS, there's even a Github project. I didn't copy the contents of those documents here since it's too much and it's a moving target.
You can also install OpenSSL with Homebrew. If you just want to have your app run on your Mac and you don't want to distribute it, this is the easiest way: you just need to link it. But if you want to distribute your app, you would need to copy the library/libraries to your app bundle and make sure the the linker finds it there. This also has the disadvantage that there's a possible "disconnect" between your app and the OpenSSL version: if in one year, you update OpenSSL with Homebrew and want to compile/link an older version of your app against the very same OpenSSL version as you've used at that time, you have a problem.

i tried today starting of 2020
install openssl with homebrew
brew install openssl
this will install openssl version 1.1d in
/usr/local/Cellar/openssl#1.1/1.1.1d/lib/
add both libcrypto.a and libssl.a
brew will not make a symbolic link to /usr/local/lib

Related

Differences between Apple LLVM and LLVM

I have Apple's command line tools version 9.1 installed and am working through an LLVM tutorial. I need to use some libraries like llvm/ADT and llvm/IR but get an error when I run the code.
main.cpp:1:10: fatal error: 'llvm/ADT/APFloat.h' file not found
#include "llvm/ADT/APFloat.h"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
I also don't seem to have tools such as the assembler. Are these things not usable with Apple's version? And can I install LLVM without conflicting with Apple's version?
Apple's fork misses most of the library,headers and command-line tools in the llvm trunk.
I suggest you compile a new llvm copy from trunk.
Conflicting depends on how you configure everything. You can:
Install your new copy to global location, where your $PATH configuration is responsible for choosing which version to use.
Install as a separate Xcode Toolchain.
Here is a build script I've been using:
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_APPEND_VC_REV=on -DLLVM_ENABLE_EH=on -DLLVM_ENABLE_RTTI=on -DLLVM_CREATE_XCODE_TOOLCHAIN=on -DCMAKE_INSTALL_PREFIX=~/Library/Developer/ ../LLVM
Running ninja install will install to global location, otherwise run ninja install-xcode-toolchain to install as a separate toolchain
In your case I suggest installing to global location to avoid the trouble of messing with CFLAGS/LDFLAGS/Header Search Path. Then remove the installation manually after you are done with the tutorial
EDIT: You might also want to check out the official build guide https://llvm.org/docs/CMake.html
For your use case, in-tree building is also a feasible option(Providing you are familiar with write cmake configs)
Actually, there is no need to build the LLVM yourself. You can get prebuilt version for your platform here: http://releases.llvm.org
In your case it would be something like this:
cd /opt
wget http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
tar xvf clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
mv clang+llvm-5.0.0-x86_64-apple-darwin llvm-5.0.0
After that you will have everything under /opt/llvm-5.0.0, e.g.:
/opt/llvm-5.0.0/bin/clang
/opt/llvm-5.0.0/bin/llvm-config
/opt/llvm-5.0.0/lib/libc++.a
etc.
P.S. I use /opt just as an example, feel free to pick any other directory that fits you best.

build libzmq on mac os x

I am trying to use ZMQ library to communicate between python and c++ code.
I downloaded the source zip from http://zeromq.org/area:download and built it for the windows by using visual studio 2010.
I need to support MAX OS X also. So I tried the same above process by using xcode.
-> I downloaded the code from http://zeromq.org/area:download "POSIX tarball".
-> extract content of zeromq-4.0.4.tar.gz which is downloaded in the above step
-> created the project on xcode
-> included all the files from zeromq-4.0.4/src and zeromq-4.0.4/inc in the xcode project
-> build
Xcode is giving an error while compiling i.e. Unsupported browser in file poller.hpp (77).
I tried to understand from the zmq website but I could not built it.
Can anybody pleas help me building the static lib for the MAC OS X
Thank you.
As per official documentation
brew install zeromq
On the zeromq download page that you reference:
To build on UNIX-like systems
If you have free choice, the most comfortable OS for developing with
ZeroMQ is probably Ubuntu.
Make sure that libtool, autoconf, automake are installed. Check
whether uuid-dev package, uuid/e2fsprogs RPM or equivalent on your
system is installed. Unpack the .tar.gz source archive. Run
./configure, followed by make. To install ZeroMQ system-wide run sudo
make install. On Linux, run sudo ldconfig after installing ZeroMQ. To
see configuration options, run ./configure --help. Read INSTALL for
more details.
Tells you pretty clearly that on Mac OS X compilation uses automake/autoconf. Instead of importing the files into Xcode, install the Xcode command-line tools and do a simple ./configure --enable-static && make to build the static library. The configure script will generate the right headers for you. This is pretty much the default way most libraries that use automake/autoconf are built...
Just use cmake described here:
git clone https://github.com/zeromq/libzmq
mkdir cmake-build && cd cmake-build
cmake .. && make -j 4
make test && make install && sudo ldconfig
I failed 2 test, 1 exception, the other time out.
But building is fine except ldconfig is not on Mac, so need to use dyld
(i am not sure this part)
But it seems working
P.S. Read INSTALL doesn't not give much info

On OS X, what is the proper setting for $QTDIR?

I'm trying to install QtROOT, and as part of the installation (specifically, the readme file in the QtROOT tarball at http://root.bnl.gov/QtRoot/downloads/qtFullRoot.tar.gz), it mentions to make sure that QTDIR is set. I've installed from the Qt 4.6.3 SDK installation for Mac OS X, and I have no such environment variable set. I've tried googling to figure out where it should be set to, but the options I've found (such as /usr/local/qt) don't exist. What should this variable be set to?
OS X 10.6.4, Qt 4.6.3, ROOT 5.26/00, QtROOT... I have no idea. :P
Thanks,
Paul
Qt's packaged installer for OSX scatters things throughout the /Developer and /Library directories rather than installing to a self-contained location in /usr/local or /opt/local as you might expect it to do on other unix-based systems.
Incidentally, Qt follows Apple's way of doing things in this respect, so it's really not wrong -- it's just different -- but it does make some 3rd party Qt applications somewhat difficult to build on OSX.
The packaged Qt installer itself has the following to say on this topic:
After a successful install, you can find most new things in /Developer. Specifically things will be located in the following places:
Qt Designer, Qt Linguist: /Developer/Applications/Qt
Qt Documentation: /Developer/Documentation/Qt
Qt Examples: /Developer/Examples/Qt
Qt Plugins: /Developer/Applications/Qt/Plugins
Qt Frameworks: /Library/Frameworks
Qt Libraries: /usr/lib
qmake, moc, uic, etc.: /Developer/Tools/Qt (symlink to /usr/bin)
Uninstall script: /Developer/Tools/uninstall-qt.py
So, it does put the libs into '/usr/lib', and it symlinks the essential Qt tools (like qmake) into '/usr/bin'. This suggests that QTDIR could be set to '/usr'. In practice however, this doesn't work because the qt headers remain buried in '/Library/Frameworks/Qt*/Headers/*.h', while builds that rely on $QTDIR will end up looking for the qt headers in "${QTDIR}/include/" instead.
The easiest way around all this is to build Qt from source. The install location will default to something like /usr/local/Trolltech/Qt-4.6.3 (note the version number, and adjust accordingly). You can override the default install location by using the -prefix option on ./configure.
A simpler approach is to let macports build it for you. This is the approach I ended up taking (and with good success). Just install macports, if you don't already have it. Then:
> sudo port selfupdate
> sudo port install qt4-mac
Macports will work its magic, and when it's done Qt will be installed, in its entirety, at /opt/local/libexec/qt4-mac.
Regardless of how you build Qt, expect a full build to take several hours. It's a very large code base.
I didn't install Qt from the installer (but compiled it myself), so I don't know the default location.
However, where you installed Qt, there is your QTDIR.
Search for qmake, it should reside in some bin/ folder. one up is QTDIR ($QTDIR/bin/qmake).
Usually it's not necessary anymore to set QTDIR these days to build a Qt project, just qmake must be in the PATH, everything else found then. But some projects might require it though (if they use a custom build system that still uses QTDIR).
I need to install LiteIDE on my mac and in the install guide, the QTDIR is necessary. I install the qt with the homebrew by brew install qt --build-from-source, it takes about 2 hours in RMBP. After the install finished, there is still no QTDIR path. By checking the build_osx.sh, i know it's just the parent folder of bin. so i set the path by export QTDIR=/usr/local/Cellar/qt/4.8.6. Then run the ./build_osx.sh again. it works.
Hope this will be helpful.

XCode: Where is GCC installed?

I've installed XCode v3.1.3 and am having difficulties using the rumored GCC that is installed along with it. -- I'm certainly able to use the XCode IDE to compile my programs but would like the flexibility of also using the command line...
Where's GCC?
Look in /Developer/usr/bin
The most likely explanation is that when you installed the Developer tools you unchecked "UNIX Development Support", so the command line tools were never installed. Delete your /Developer/ directory and do a clean install of the tools; make sure to select "configure" during the installation process and ensure that the appropriate items are checked.
In /usr/bin you should find gcc-4.0 and gcc-4.2 and then there will be a symbolic link gcc which points to one of these (usually gcc-4.2).
As always, you can find out where any available command in your PATH is located using which, e.g.
$ which gcc

What would be the best way to install (distribute) dynamic libraries in Mac OSX using CMake/Cpack?

I have a project whose artifacts are two dynamic libraries, let's say libX.dylib and libY.dylib (or .so for linux distributions). There are no executables.
Now I would like to distribute these libraries. Since I already use CMake to compile it, I looked at CPack and successfully generated .tgz and .deb packages for Linux. However, for Mac OSX I have no idea and the CPack Wiki about its generators did not help me much. I managed to generate a PackageMaker package, but as clearly stated at this packagemaker howto, there is no uninstall option when using this util. I then read a bit about Bundles, but I feel lost specially since I have no executable.
Question: What is the correct way to generate a package for Mac OSX using CPack?
My ideal scenario would be either something that installs as easily as a bundle or as a deb file in debian/ubuntu.
Thanks for your help
Edit
One more detail: the code to one of these libraries is not open, so I can't expect the users to do a cmake; make; make install
That's why I want a .deb, .tar.gz, bundle or whatsoever.
It depends on whether you want to install it the UNIX-y way (which is totally an ok thing to do, and actually my own preference as a Mac user) or if you want to install it as a Mac OS X Framework.
To install the libraries the UNIX-y way, you can use:
INSTALL(TARGETS target1 target2 DESTINATION lib)
In the above, replace target1 and target2 with the names of the targets that resulted in libX.dylib and libY.dylib being generated (i.e. whatever you used in ADD_LIBRARY). You can use the variable CMAKE_INSTALL_PREFIX in order to determine where the library ultimately ends up... with the above, if you set CMAKE_INSTALL_PREFIX to /usr/local, then it will install the libraries in /usr/local/lib
Edit
Based on your update, you may find Component Install with CPack and CPack Mac OS X PackageMaker Generator to be of interest. Since you will be installing libraries into the system, the PackageMaker generator is the one you should use. If you were merely distributing an application, then creating a ".app" bundle and distributing it in a ".dmg" would be the proper thing to do. PackageMaker is installed on Mac OS X when you install the Xcode Developer Tools. To package a ".app" bundle in a ".dmg", you can use the Mac OS X disk utility application or its associated commandline tools.

Resources