libtins works on several architectures commonly used in embedded
systems, such as ARM and MIPS. In this section we'll have
a look at how you can cross-compile the library so that you can use it
on those architectures.
Through this section, I'm going to use a MIPS toolchain that
I've compiled and installed. Getting the right toolchain is not covered
in this tutorial.
My toolchain is installed in /opt/mips_linux_toolchain/. For
example, in /opt/mips_linux_toolchain/bin/ I've got the compiler,
linker and other utilities:
I've already cross-compiled libpcap and located its headers in
/opt/mips_linux_toolchain/include/ and shared object in
/opt/mips_linux_toolchain/lib/:
Compiling
Now that you've got a picture of how my environment is setup, let's go
straight to the compilation process.
As usual, we have to execute CMake so it configures the project:
Let's look at each flag used:
CMAKE_FIND_ROOT_PATH: this indicates the root path in
which the toolchain is installed.
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY: this is not required,
but it's a useful flag. It tells CMake to only look for
libraries in the path provided by the previous option. Without it,
it could detect another installation of them, even if they're
compiled for another architecture.
CMAKE_CXX_COMPILER: this indicates the C++ compiler that
we are going to use
LIBTINS_ENABLE_WPA2: since I haven't cross-compiled
libcrypto, I've disabled this feature.
CROSS_COMPILING indicates we're doing a cross compiled build.
In this case, since libpcap's headers and shared objects are
located inside the toolchain directory, there's no need to do anything
to help CMake locate them. Otherwise, you would need to set
the PCAP_ROOT_DIR option, providing the library path as its
value.
Then just run make as usual:
And you are done. When you execute the configure script, you can use
the CMAKE_INSTALL_PREFIX option, as usual, to indicate the path
in which to install the library.