Cross Compiling: Difference between revisions
No edit summary |
No edit summary |
||
Line 253: | Line 253: | ||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) | ||
|} | |||
{| class="mw-collapsible mw-collapsed wikitable" | |||
! CMakeLists.txt example | |||
|- | |||
| | |||
cmake_minimum_required(VERSION 2.8) | |||
# MDM silently append relative paths to absolute paths without warnings | |||
cmake_policy(SET CMP0015 NEW) | |||
# MDM Set the executable name! | |||
# project(nop-bigress-client-c) | |||
project(nop-client) | |||
# ------------------------------- | |||
# To ensure we get a static build. | |||
# For this to work, the linker needs to be able to find all libraries. | |||
# Make sure they are included next in [include|link]_directories. | |||
# Also make sure they are included in TARGET_LINK_LIBRARIES. | |||
# ------------------------------- | |||
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") | |||
SET(BUILD_SHARED_LIBRARIES OFF) | |||
SET(CMAKE_EXE_LINKER_FLAGS "-static") | |||
# ------------------------------- | |||
# ------------------------------- | |||
# MDM For cross compile, we must provide all lib paths. | |||
# We have ours: /home/m/development/armv4 | |||
# And the toolchain is here: /opt/crosstool-source-v4/arm-926ejs-linux-gnueabi | |||
# ------------------------------- | |||
include_directories(/home/m/development/armv4/include /opt/crosstool-source-v4/arm-926ejs-linux-gnueabi/include) | |||
link_directories(/home/m/development/armv4/lib /opt/crosstool-source-v4/arm-926ejs-linux-gnueabi/lib) | |||
# ------------------------------- | |||
# ------------------------------- | |||
# MDM Build *everything* in ./src | |||
# ------------------------------- | |||
# WARNING: [make] won't pick up new files until you rerun [cmake]. | |||
# Change this to be explicit if that becomes a problem. | |||
# Easy to change: | |||
# set( NOP_SOURCES src/nop_client.c src/helpers.c ) | |||
aux_source_directory(./src NOP_SOURCES) | |||
add_executable( | |||
${PROJECT_NAME} | |||
${NOP_SOURCES} | |||
) | |||
# The main linker line used to create the executable | |||
# MDM added [c] after ubuntu xenial started giving segfaults in dl -> openssl - didn't help! | |||
# see http://stackoverflow.com/questions/7526255/unknown-reference-to-dlopen-in-dlopen | |||
# TARGET_LINK_LIBRARIES(${PROJECT_NAME} websockets ssl crypto pthread dl z c) | |||
# MDM NO LINKING since we built websockets static! no, this doesn't work... | |||
#TARGET_LINK_LIBRARIES(${PROJECT_NAME} websockets) | |||
# MDM cJSON requires floor + pow, in the C math lib, so we add "m" | |||
TARGET_LINK_LIBRARIES(${PROJECT_NAME} websockets ssl crypto pthread dl z c m) | |||
|} | |} |
Latest revision as of 20:02, 29 November 2016
Issues:
- need cross compile toolchain
- you need to find or build an entire toolchain environment; ubuntu has some, others have some, Crosstool-NG will build one from scratch
- for autotools, you typically need to define tools like ar, gcc, g++ in the build script
- for cmake, you typically need a toolchain file to specify details
- need to cross compile any dependencies (static link what you can)
- need to match the libraries on target machine for any dynamic linking requirements
- need to match the build to the target kernel (or you might get "kernel too old")
Expandlibz example |
---|
Expandopenssl example |
---|
Expandmulti-lib complete example |
---|
Expandcmake toolchain file example |
---|
ExpandCMakeLists.txt example |
---|