Cmake Crosscompilation for LPC ARM target

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Cmake Crosscompilation for LPC ARM target

3,195 Views
lisethalvaradod
Contributor I

Hi,
My question is how can I cross compile a library given its sources and cmake files in order to use it in my project inside mcuExpresso.
Addendum: in that project I will use FreeRtos.

Detail of what I tried follows:

I've got a library distributed as source files along with .cmake files. Everything is ready to be used with cmake.
I've already successfully done a build for my host environment witch is Ubuntu 16 64bit.
What I'm trying to do is cross compiling from Ubuntu host architecture to target LPC ARM architecture by the use of cmake.
For this reason I've written a tiny cmake_toolchain_file that is called through this command:
---------------------------------------------------------------
cmake -G "Eclipse CDT 4 - Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=$TOOL_FILE $SRC_DIR
--------------------------------------------------------------
As you can see I want to produce a .project file for eclipse IDE as I supposed to successively import it in mcuExpresso IDE.
The cmake toolchain file is a little modifcation of what this lib suggests to use:
-------------------------------------------------------------------------------------------------
SET(CMAKE_SYSTEM_NAME Generic)
INCLUDE(CMakeForceCompiler)

CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-g++ GNU)
SET(CMAKE_C_FLAGS "-Wall -ffunction-sections -fdata-sections -fno-builtin-memcpy -gdwarf-2 -mthumb-interwork -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -O0 -g3 -c -MMD -MP ")
SET(CMAKE_EXE_LINKER_FLAGS "-nostdlib -nostartfiles -Wl,--gc-sections -Wl,--wrap=malloc -Wl,--wrap=calloc -Wl,--wrap=realloc -Wl,--wrap=free -Wl,--wrap=_malloc_r -Wl,--wrap=_calloc_r -Wl,--wrap=_realloc_r -Wl,--wrap=_free_r -Wl,--defsym -Wl,PAGE_SIZE=0 -Wl,--start-group -lgcc -lc -lm -lstdc++ -Wl,--end-group")
--------------------------------------------------------------------------------------------

The compiler and linker flags used are taken from those suggested by the lib man page but edited according to those issued by mcuExpresso IDE to the compiler and linker.
What here is missing is the option: -spec=redlib.spec that is instead supplied by the IDE.
Running this script produce the following output:
-----------------------------------------------------------------------------------------------------------------------------------------------
Determining if the include file stdio.h exists failed with the following output:
Change Dir: /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_6ef81/fast"
/usr/bin/make -f CMakeFiles/cmTC_6ef81.dir/build.make CMakeFiles/cmTC_6ef81.dir/build
make[1]: Entering directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_6ef81.dir/CheckIncludeFile.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_6ef81.dir/CheckIncludeFile.c.obj -c /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_6ef81
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_6ef81.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_6ef81.dir/CheckIncludeFile.c.obj -o cmTC_6ef81
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_6ef81.dir/build.make:97: recipe for target 'cmTC_6ef81' failed
make[1]: *** [cmTC_6ef81] Error 1
make[1]: Leaving directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_6ef81/fast' failed
make: *** [cmTC_6ef81/fast] Error 2


Determining if the include file stddef.h exists failed with the following output:
Change Dir: /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_d02a3/fast"
/usr/bin/make -f CMakeFiles/cmTC_d02a3.dir/build.make CMakeFiles/cmTC_d02a3.dir/build
make[1]: Entering directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_d02a3.dir/CheckIncludeFile.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_d02a3.dir/CheckIncludeFile.c.obj -c /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_d02a3
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d02a3.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_d02a3.dir/CheckIncludeFile.c.obj -o cmTC_d02a3
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_d02a3.dir/build.make:97: recipe for target 'cmTC_d02a3' failed
make[1]: *** [cmTC_d02a3] Error 1
make[1]: Leaving directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_d02a3/fast' failed
make: *** [cmTC_d02a3/fast] Error 2


Determining if the include file string.h exists failed with the following output:
Change Dir: /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_d039a/fast"
/usr/bin/make -f CMakeFiles/cmTC_d039a.dir/build.make CMakeFiles/cmTC_d039a.dir/build
make[1]: Entering directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_d039a.dir/CheckIncludeFile.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_d039a.dir/CheckIncludeFile.c.obj -c /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_d039a
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d039a.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_d039a.dir/CheckIncludeFile.c.obj -o cmTC_d039a
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_d039a.dir/build.make:97: recipe for target 'cmTC_d039a' failed
make[1]: *** [cmTC_d039a] Error 1
make[1]: Leaving directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_d039a/fast' failed
make: *** [cmTC_d039a/fast] Error 2


Determining if the include file stdlib.h exists failed with the following output:
Change Dir: /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_b0493/fast"
/usr/bin/make -f CMakeFiles/cmTC_b0493.dir/build.make CMakeFiles/cmTC_b0493.dir/build
make[1]: Entering directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_b0493.dir/CheckIncludeFile.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_b0493.dir/CheckIncludeFile.c.obj -c /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_b0493
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_b0493.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_b0493.dir/CheckIncludeFile.c.obj -o cmTC_b0493
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_b0493.dir/build.make:97: recipe for target 'cmTC_b0493' failed
make[1]: *** [cmTC_b0493] Error 1
make[1]: Leaving directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_b0493/fast' failed
make: *** [cmTC_b0493/fast] Error 2


Determining if the include file stdint.h exists failed with the following output:
Change Dir: /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_e0988/fast"
/usr/bin/make -f CMakeFiles/cmTC_e0988.dir/build.make CMakeFiles/cmTC_e0988.dir/build
make[1]: Entering directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_e0988.dir/CheckIncludeFile.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_e0988.dir/CheckIncludeFile.c.obj -c /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_e0988
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_e0988.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_e0988.dir/CheckIncludeFile.c.obj -o cmTC_e0988
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_e0988.dir/build.make:97: recipe for target 'cmTC_e0988' failed
make[1]: *** [cmTC_e0988] Error 1
make[1]: Leaving directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_e0988/fast' failed
make: *** [cmTC_e0988/fast] Error 2


Determining if the include file stdarg.h exists failed with the following output:
Change Dir: /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_07955/fast"
/usr/bin/make -f CMakeFiles/cmTC_07955.dir/build.make CMakeFiles/cmTC_07955.dir/build
make[1]: Entering directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_07955.dir/CheckIncludeFile.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_07955.dir/CheckIncludeFile.c.obj -c /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_07955
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_07955.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_07955.dir/CheckIncludeFile.c.obj -o cmTC_07955
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_07955.dir/build.make:97: recipe for target 'cmTC_07955' failed
make[1]: *** [cmTC_07955] Error 1
make[1]: Leaving directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_07955/fast' failed
make: *** [cmTC_07955/fast] Error 2


Determining if the include file syslog.h exists failed with the following output:
Change Dir: /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_a63be/fast"
/usr/bin/make -f CMakeFiles/cmTC_a63be.dir/build.make CMakeFiles/cmTC_a63be.dir/build
make[1]: Entering directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_a63be.dir/CheckIncludeFile.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_a63be.dir/CheckIncludeFile.c.obj -c /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c
/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c:1:20: fatal error: syslog.h: No such file or directory
#include <syslog.h>
^
compilation terminated.
CMakeFiles/cmTC_a63be.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_a63be.dir/CheckIncludeFile.c.obj' failed
make[1]: *** [CMakeFiles/cmTC_a63be.dir/CheckIncludeFile.c.obj] Error 1
make[1]: Leaving directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_a63be/fast' failed
make: *** [cmTC_a63be/fast] Error 2


Determining if the include file time.h exists failed with the following output:
Change Dir: /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_06241/fast"
/usr/bin/make -f CMakeFiles/cmTC_06241.dir/build.make CMakeFiles/cmTC_06241.dir/build
make[1]: Entering directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_06241.dir/CheckIncludeFile.c.obj
/usr/bin/arm-none-eabi-gcc -o CMakeFiles/cmTC_06241.dir/CheckIncludeFile.c.obj -c /home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp/CheckIncludeFile.c
Linking C executable cmTC_06241
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_06241.dir/link.txt --verbose=1
/usr/bin/arm-none-eabi-gcc CMakeFiles/cmTC_06241.dir/CheckIncludeFile.c.obj -o cmTC_06241
/usr/lib/gcc/arm-none-eabi/4.9.3/../../../arm-none-eabi/lib/libc.a(lib_a-exit.o): In function `exit':
/build/newlib-5zwpxE/newlib-2.2.0+git20150830.5a3d536/build/arm-none-eabi/newlib/libc/stdlib/../../../../../newlib/libc/stdlib/exit.c:70: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_06241.dir/build.make:97: recipe for target 'cmTC_06241' failed
make[1]: *** [cmTC_06241] Error 1
make[1]: Leaving directory '/home/user/Desktop/MCL/MCL_BUILD/NXP/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_06241/fast' failed
make: *** [cmTC_06241/fast] Error 2


----------------------------------------------------------------------------------------------------------------------------------------------------------------

From this output it is known that the function _exit is not defined nor implemented (I do not think I do have to provide a fake implementation for it..).
So the question is how do I avoid this error?
How can I build this library for ARM target?
The arm-none-eabi used is resident in my host, is not the one in the toolchain, but I've tried also that one with this call before calling the script:
export PATH=/usr/local/mcuexpressoide-10.0.2_411/ide/tools:$PATH
but nothing changed.
I've also tried to add -spec=nosys.spec and -spec=redlib.spec as input option for the compiler and linker but it always fail with same output.

Waiting for your help, thanks

0 Kudos
2 Replies

1,778 Views
m4l490n
Contributor V

Check out this SO answer CMake: The C Compiler is not able to compile a simple test program. It contains the answer to your issue.

But it is basically that in embedded systems you don't "exit" main like in a PC application. you don't have a main like:

int main(int argc) { return argc - 1; }

So there is no standard "__exit" defined.

0 Kudos

1,778 Views
converse
Senior Contributor V

You are missing the semixosting library which implements the low-level functions required by the C library. See

https://community.nxp.com/thread/389153 

A couple of points though:

1. On an embedded system what, exactly, do you expect exit() to do? AFAIK, the default implementation is the enter a while(1) loop

2. In the log output, above, you are building each file individually. Is this correct, and they are all standalone applications, or did you mean to link all of the object files into a single executable?

0 Kudos