gccarmcross-compilingembedded-linuxcpp-netlib

How to build static library .a for ARM using cross compiler?


I was trying to compile statically cpp-netlib and rpclib for ARM device.(Same as ZEDboard)

Everything i did is changed the compiler and system settings in CMakeLists.txt file.

    set(CMAKE_SYSTEM_NAME Linux)
    set(CMAKE_SYSTEM_PROCESSOR arm)

    set(CMAKE_SYSROOT /home/a/buildroot-2018.05/output/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/)
    set(tools /home/a/buildroot-2018.05/output/host/bin/)
    set(CMAKE_C_COMPILER ${tools}arm-buildroot-linux-uclibcgnueabihf-gcc)
    set(CMAKE_CXX_COMPILER ${tools}arm-buildroot-linux-uclibcgnueabihf-g++)

    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

After Makefile is created by cmake i ran make and no output has been produced. As i understand build directories should appear.

For the rpclib things went better. It has compiled the librpc.a file but unftunately its not linking to my program.

arm-buildroot-linux-uclibcgnueabihf-g++ -I/home/a/rpclib/include/ -Xlinker -static /home/a/rpclib/librpc.a main.cpp

produces this output:

/home/a/buildroot-2018.05/output/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/../../../../arm-buildroot-linux-uclibcgnueabihf/bin/ld: cannot find -lgcc_s
/home/a/buildroot-2018.05/output/host/lib/gcc/arm-buildroot-linux-uclibcgnueabihf/6.4.0/../../../../arm-buildroot-linux-uclibcgnueabihf/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status

but there is gcc_s in the sysroot directory.

~/buildroot-2018.05/output/host/arm-buildroot-linux-uclibcgnueabihf$ find ./ -name *gcc_s*

./sysroot/lib/libgcc_s.so
./sysroot/lib/libgcc_s.so.1
./sysroot/usr/include/boost/asio/detail/gcc_sync_fenced_block.hpp
./sysroot/usr/include/boost/atomic/detail/caps_gcc_sync.hpp
./sysroot/usr/include/boost/atomic/detail/ops_gcc_sync.hpp
./sysroot/usr/include/boost/atomic/detail/ops_gcc_sparc.hpp
./sysroot/usr/include/boost/atomic/detail/caps_gcc_sparc.hpp
./sysroot/usr/include/boost/smart_ptr/detail/sp_counted_base_gcc_sparc.hpp
./lib/libgcc_s.so
./lib/libgcc_s.so.1

I guess i am missing something important about cross-compilation. So basically i have 3 questions:


Solution

  • Actually buildroot supports building static libraries.
    Steps to build a custom library using buildroot:

    1. Create a folder inside buildroot/package folder with the name of target library. e.g. my path looks like this /home/a/buildroot-2018.05/package/rpclib
    2. Create Config.in file in target library dir with the needed parameters which can be checked in buildroot manual or better
    3. Create [package-name].mk
    4. Then add entry in /buildroot/package/Config.in
    5. Then package can be marked for installation in menuconfig/target pacckages

    My Config.in file for rpclib

    config BR2_PACKAGE_RPCLIB
    bool "rpclib"
    depends on BR2_INSTALL_LIBSTDCPP
    depends on BR2_USE_WCHAR
    help
      rpclib is a modern C++ msgpack-RPC server and client library
    
      http://rpclib.net
    

    My rpclib.mk file

    RPCLIB_VERSION = v2.2.1
    RPCLIB_SITE = $(call github,rpclib,rpclib,$(RPCLIB_VERSION))
    RPCLIB_INSTALL_STAGING = YES
    RPCLIB_INSTALL_TARGET = NO
    RPCLIB_CONF_OPTS = -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF
    
    $(eval $(cmake-package))
    

    And entry in Config.in in the buildroot/packages dir

    source "package/rpclib/Config.in"
    

    After executing make i received

    ./output/host/arm-buildroot-linux-uclibcgnueabihf/sysroot/usr/lib/librpc.a