Environment

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:

$ ls /opt/mips_linux_toolchain/bin/
mips-linux-gnu-addr2line  mips-linux-gnu-gccbug   mips-linux-gnu-ranlib
mips-linux-gnu-ar         mips-linux-gnu-gcov     mips-linux-gnu-readelf
mips-linux-gnu-as         mips-linux-gnu-gdb      mips-linux-gnu-run
mips-linux-gnu-c++        mips-linux-gnu-gdbtui   mips-linux-gnu-size
mips-linux-gnu-c++filt    mips-linux-gnu-gprof    mips-linux-gnu-strings
mips-linux-gnu-cpp        mips-linux-gnu-ld       mips-linux-gnu-strip
mips-linux-gnu-elfedit    mips-linux-gnu-ld.bfd   
mips-linux-gnu-g++        mips-linux-gnu-nm       
mips-linux-gnu-gcc        mips-linux-gnu-objcopy
mips-linux-gnu-gcc-4.4.6  mips-linux-gnu-objdump

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/:

$ ls /opt/mips_linux_toolchain/include/
pcap  pcap.h 
$ ls /opt/mips_linux_toolchain/lib/libpcap*
/opt/mips_linux_toolchain/lib/libpcap.a
/opt/mips_linux_toolchain/lib/libpcap.so
/opt/mips_linux_toolchain/lib/libpcap.so.1
/opt/mips_linux_toolchain/lib/libpcap.so.1.3.0

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:

# Create and move into the build directory
mkdir build
cd build
# Configure the project
cmake ../ -DCMAKE_FIND_ROOT_PATH=/opt/mips_linux_toolchain/ \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_CXX_COMPILER=/opt/mips_linux_toolchain/bin/mips-linux-gnu-g++ \
-DLIBTINS_ENABLE_WPA2=0 \
-DCROSS_COMPILING=1

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:

make

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.