Friday, July 15, 2016

Compile a third party library in a linux system(ubunut, ARM etc) or Cross Compilation

1. First extract the library

2. Read Readme or Install file comes with library.

3. If its contain Config, config or configure or Configure file then first execute the -h or --help command to see the options that library provide to configure the this library before make. Like --host= option where you could tell for which architecture you are willing to compile this library( This called cross compilation). when you compile a library for another different architecture which is different than your current build environment. Like from ubuntu 64 bit Desktop i could make library for ARM architecture.


you could specify your g++, gcc, ranlib, ar, strip through the configure command like this

./configure --host=arm --enable-shared CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++ AR=arm-none-linux-gnueabi-ar RANLIB=arm-none-linux-gnueabi-ranlib STRIP=arm-none-linux-gnueabi-strip

You must be careful in console output after configure command execution below some important point focused

root@user-vm2:/home/user/Desktop/AnyConnect/Raspberry(ARM_V7)_Environment/3rd_Party_Cavium/expat-2.1.1# ./configure --host=aarch64 --enable-shared
checking build system type... x86_64-unknown-linux-gnu
checking host system type... aarch64-unknown-none
checking how to print strings... printf
checking for aarch64-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed

You can see that your running system is x86_64-unknown-linux-gnu and your host/targeted/cross compile system is aarch64-unknown-none

We must follow the CPU-COMPANY-SYSTEM triplet convention to determine host name.

This gives you a bit more information because your host is aarch64-unknown-none where none is not acceptable
so we must give a valid or correct or exact host name by --host= parameter in configure command.

Now the question is where we could find the exact host name what we desired

There is documentation for target triplets. The config.sub file that comes with the tarball is the "definitive" list for that tarball (until it's packaged with a later version of autotools). The most helpful information will come from how the compiler prefix (and other binutils) are named (in this example arm-none-linux-gnueabi-) collected from Stack Overflow



We can define our tool chain path using ./configure command 

Some influential environment variables:
  CC           C compiler command
  CFLAGS       C compiler flags
  LDFLAGS      linker flags, e.g. -L<lib dir> if you have libraries in a 
               nonstandard directory <lib dir>
  LIBS         libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS     (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if 
               you have headers in a nonstandard directory <include dir>
  CPP          C preprocessor


env CPPFLAGS="-I/usr/local/bdb/include -I/usr/local/ssl/include" LDFLAGS="-L/usr/local/bdb/lib -L/usr/local/ssl/lib" ./configure --with-crypt --with-bdb --with-tls
























Thursday, July 14, 2016

How to know for which architecture a library or executable was build.

To know details about your executable of library you could execute any of this command.

The 'file <file>' command will give you the architecture, you could also use 'objdump -f <file>'

Out put in your console would be more or less like below

libexpat.so.1.6.0: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped

we can see above ARM aarch64 was the architecture for this library build.

Note. Your file and objdump executable must be same with the architecture of where your executable was build.

Where to save environment variable in linux system permanently

some time we need to set our user defined location where we have some library's to use when ld.so, ld-linux.so* - dynamic linker/loader search for library when its start linking for making executable of library.


we just can add the library path in this location's file
/etc/environment