Cross compile with cmake cannot link test - cmake

I try to cross compile a library (Wt) using CMake (2.8.12.2). I get always errors which tell me that it is not able to compile a simple test program.
I do not know how to make cmake to look into the right path for getting object files.
My development and target plattform is Linux.
The error log looks like this
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/bin/arm-reed-linux-gnueabi/arm-reed-linux-gnueabi-gcc
Build flags: ;-O2;-pipe;-g;-feliminate-unused-debug-types;
Id flags:
The output was:
1
/opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/libexec/arm-reed-linux-gnueabi/gcc/arm-reed-linux-gnueabi/5.3.0/real-ld: cannot find crt1.o: No such file or directory
/opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/libexec/arm-reed-linux-gnueabi/gcc/arm-reed-linux-gnueabi/5.3.0/real-ld: cannot find crti.o: No such file or directory
...
Here is my tool chain file. I could skip the test (See CMAKE_C_COMPILER_WORKS) but then I get later similar problems:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
# Compiler and linker
SET(CMAKE_C_COMPILER "/opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/bin/arm-reed-linux-gnueabi/arm-reed-linux-gnueabi-gcc")
SET(CMAKE_CXX_COMPILER "/opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/bin/arm-reed-linux-gnueabi/arm-reed-linux-gnueabi-g++")
SET(COMPILE_FLAGS " -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a8 --sysroot=/opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi")
SET(CMAKE_EXE_LINKER_FLAGS " -O2 -v -o --sysroot=/opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi ")
# Paths
SET(CMAKE_PREFIX_PATH /opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi/usr/)
SET(CMAKE_SYSROOT /opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi/)
SET(CMAKE_FIND_ROOT_PATH /opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi/)
SET(CMAKE_COLOR_MAKEFILE ON)
set(SHARED_LIBS OFF)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# skip the compiler tests
# set(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
# set(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
And here is a tree view of my system. I pruned it to show the relevant part.
/opt/rhl/0.01/sysroots
├── cortexa8hf-neon-reed-linux-gnueabi
│   ├── bin
│   ├── lib
│   ├── usr
│   │   ├── bin
│   │   ├── include
│   │   ├── lib
│   │   │   ├── crt1.o -> cmake cannot find this file
│   │   │   ├── crti.o -> cmake cannot find this file
│   │   ├── share
│   │   └── src
│   │   ├── gcc-runtime
│   │   │   └── 5.3.0-r0
└── x86_64-rhlsdk-linux
├── lib
├── sbin
├── usr
│   ├── bin
│   │   │   ├── arm-reed-linux-gcc -> ../arm-reed-linux-gnueabi/arm-reed-linux-gnueabi-gcc
│   │   ├── arm-reed-linux-gnueabi
│   │   │   ├── arm-reed-linux-gnueabi-gcc -> The C compiler
│   ├── include
│   ├── lib
│   ├── libexec

Related

Unable to download Tensorflow C Language Bindings as an ExternalProject

I'm trying to include the C language bindings for Tensorflow found at https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.5.0.tar.gz in my CMake Project. Unfortunately, it seems as thought nothing is being downloaded, as the TENSORFLOW-prefix/src/TENSORFLOW directory is empty. I'm new to CMake and am not sure where I am going wrong. Any help would be appreciated.
Relevant source:
cmake_minimum_required(VERSION 3.17)
include(ExternalProject)
project(tfexec)
set(CMAKE_CXX_STANDARD 17)
ExternalProject_Add(TENSORFLOW
URL "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-gpu-linux-x86_64-2.5.0.tar.gz"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
LOG_DOWNLOAD 1
LOG_CONFIGURE 1
LOG_BUILD 1
LOG_INSTALL 1
)
ExternalProject runs at build time, so you actually need to run your build for this to do anything. This is what I see; it seems to be working fine:
alex#Alex-Desktop:~/test$ cmake-3.17 -S . -B build -DCMAKE_BUILD_TYPE=Release
...
-- Configuring done
-- Generating done
-- Build files have been written to: /home/alex/test/build
alex#Alex-Desktop:~/test$ cmake --build build/ -- -v
...
alex#Alex-Desktop:~/test$ tree build/TENSORFLOW-prefix/src/TENSORFLOW
build/TENSORFLOW-prefix/src/TENSORFLOW
├── LICENSE
├── THIRD_PARTY_TF_C_LICENSES
├── include
│   └── tensorflow
│   ├── c
│   │   ├── c_api.h
│   │   ├── c_api_experimental.h
│   │   ├── c_api_macros.h
│   │   ├── eager
│   │   │   ├── c_api.h
│   │   │   ├── c_api_experimental.h
│   │   │   └── dlpack.h
│   │   ├── tensor_interface.h
│   │   ├── tf_attrtype.h
│   │   ├── tf_datatype.h
│   │   ├── tf_file_statistics.h
│   │   ├── tf_status.h
│   │   ├── tf_tensor.h
│   │   └── tf_tstring.h
│   └── core
│   └── platform
│   ├── ctstring.h
│   └── ctstring_internal.h
└── lib
├── libtensorflow.so -> libtensorflow.so.2
├── libtensorflow.so.2 -> libtensorflow.so.2.5.0
├── libtensorflow.so.2.5.0
├── libtensorflow_framework.so -> libtensorflow_framework.so.2
├── libtensorflow_framework.so.2 -> libtensorflow_framework.so.2.5.0
└── libtensorflow_framework.so.2.5.0
7 directories, 23 files

How to compile all the libraries as static but one as shared?

My folder structure is like that:
├── SubLibA
│   ├── CMakeLists.txt
│   ├── include
│   │   └── SubLibA.h
│   └── SubLibA.cpp
├── SubLibB
│   ├── CMakeLists.txt
│   ├── include
│   │   └── structs.h
│   └── SubLibB.cpp
└── SharedLib
├── CMakeLists.txt
├── include
│   └── SharedLib.h
├── SharedLib.cpp
└── SharedLib.h
My global CMakeLists.txt looks like this:
add_subdirectory(SubLibA)
add_subdirectory(SubLibB)
add_subdirectory(SharedLib)
They all compile as static by default.
SharedLib depends on SubLibB that depends on SubLibA.
The dependent libraries SharedLib and SubLibB have:
#SubLibB
target_link_libraries(${PROJECT_NAME}
SubLibA::SubLibA
)
#SharedLib
target_link_libraries(${PROJECT_NAME}
SubLibB::SubLibB
)
Running cmake .. -DBUILD_SHARED_LIBS=ON compiles all the three libs as shared library...
Since they are tightly dependent, I'd like to keep them in the same repository with a unique CMakeLists.txt that compiles them all at once. I want to use the power of Modern CMake with the least hard-coded file and custom files as possible to keep a straightforward maintenance.
Try setting the variable within cmake:
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(SubLibA)
add_subdirectory(SubLibB)
set(BUILD_SHARED_LIBS ON)
add_subdirectory(SharedLib)
set(BUILD_SHARED_LIBS OFF)
If you want SubLibA and SubLibB always be static libraries you can use the STATIC keyword on the add_library command, e.g. add_library(SubLibA STATIC ${SOURCES}) By omitting the keyword for SharedLib you are still free to build it as static or shared lib by setting -DBUILD_SHARED_LIBS=ON on the CMake command line.

add_custom_command for copy header files not working

This is my project tree-like format :
├── cmake
│  └── CopyHeaderFiles.cmake
├── CMakeLists.txt
├── common
│   ├── CMakeLists.txt
│   ├── Headers
│   │   ├── CMakeLists.txt
│   │   ├── criticalmessage.h
│   └── Src
│   ├── CMakeLists.txt
│   ├── criticalmessage.cpp
├── includes
│   └── CMakeLists.txt
├── main.cpp
As you see i have a module (common) in my project, my goal is copy all headers file from
PROJECT_SOURCE_DIR/common/Headers to PROJECT_BINARY_DIR/includes with add_custom_command.
this is common/CMakeLists.txt
cmake_minimum_required (VERSION 3.0)
set(MODULE_NAME common)
add_subdirectory(Headers)
add_subdirectory(Src)
include(${PROJECT_SOURCE_DIR}/cmake/CopyHeaderFiles.cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lpthread")
include_directories("${CMAKE_SOURCE_DIR}/common/Headers" )
add_library(${MODULE_NAME} STATIC ${SRC_LIST} ${INCLUDE_LIST})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
And content of cmake/HeaderFiles.cmake:
foreach( headerfile ${INCLUDE_LIST})
add_custom_command(
OUTPUT ${headerfile}
COMMAND ${CMAKE_COMMAND} -E copy
"${PROJECT_SOURCE_DIR}/${MODULE_NAME}/Headers/${headerfile}"
"${PROJECT_BINARY_DIR}/includes"
)
endforeach( headerfile )
But no files exist in include directory and always be empty after build my project.
Where am i wrong?

cmake out of source build not working for nested source directories

I am having a directory structure of my source code as follows:
.
├── build
├── CMakeLists.txt
├── libs
│   ├── CMakeLists.txt
│   ├── ext
│   │   └── include
│   │   └── json.hpp
│   └── int
│   ├── CMakeLists.txt
│   └── net
│   ├── CMakeFiles
│   │   ├── CMakeDirectoryInformation.cmake
│   │   └── progress.marks
│   ├── cmake_install.cmake
│   ├── CMakeLists.txt
│   ├── include
│   │   ├── connection.hpp
│   │   └── conn_manager.hpp
│   ├── Makefile
│   └── src
│   ├── CMakeFiles
│   │   ├── CMakeDirectoryInformation.cmake
│   │   ├── libs.dir
│   │   │   ├── build.make
│   │   │   ├── cmake_clean.cmake
│   │   │   ├── cmake_clean_target.cmake
│   │   │   ├── DependInfo.cmake
│   │   │   ├── depend.make
│   │   │   ├── flags.make
│   │   │   ├── link.txt
│   │   │   └── progress.make
│   │   └── progress.marks
│   ├── cmake_install.cmake
│   ├── CMakeLists.txt
│   ├── connection.cpp
│   ├── conn_manager.cpp
│   └── Makefile
└── main
├── CMakeLists.txt
├── config
│   └── config.json
└── srcs
├── CMakeLists.txt
├── main.cpp
├── samvaadak.cpp
└── samvaadak.hpp
"build" is a folder from which I am running cmake. It runs and creates the final output executable inside build/dist/bin. But it also creates lot of intermediate inside the source tree (libs and main) and making it cluttered.
The top level CMakeLists.txt file looks like this.
project (samvaadak)
subdirs(main libs)
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/bin)
Intermediate CMakeLists.txt files have the following content:
subdirs(src)
And, the CMakeLists.txt file for inner folder(s) where the source files are present, is like this:
include_directories(${samvaadak_SOURCE_DIR}/libs/int/net/include)
include_directories(${samvaadak_SOURCE_DIR}/libs/ext/include)
add_library(nettu conn_manager.cpp connection.cpp)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/dist/bin)
How to tell cmake that build outside of libs and main folders and just build everything inside build?
You can disable in source builds:
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
Also recommended:
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
They need to be used before the first project() command.

Which elm package versions are installed?

elm-package can manage dependencies for elm, but the only commands it supports (as of version 0.18.0) are install, publish, bump and diff according to running it without arguments. I was expecting something like elm-package list to show the installed packages.
Is there a command to list the currently installed elm package versions?
I think there is no one, but you can execute tree elm-stuff/packages -L 3 --noreport in your command line.
You will get a tree like this:
elm-stuff/packages
├── debois
│   ├── elm-dom
│   │   └── 1.2.3
│   └── elm-mdl
│   └── 8.1.0
├── elm-lang
│   ├── core
│   │   └── 5.1.1
│   ├── dom
│   │   └── 1.1.1
│   ├── html
│   │   └── 2.0.0
│   ├── http
│   │   └── 1.0.0
│   ├── mouse
│   │   └── 1.0.1
│   ├── virtual-dom
│   │   └── 2.0.4
│   └── window
│   └── 1.0.1
├── mgold
│   └── elm-date-format
│   └── 1.2.0
└── thaterikperson
└── elm-strftime
You can also just do cat elm-stuff/exact-dependencies.json, but there is no guarantee of have them installed:
{
"debois/elm-mdl": "8.1.0",
"elm-lang/virtual-dom": "2.0.4",
"elm-lang/mouse": "1.0.1",
"mgold/elm-date-format": "1.2.0",
"elm-lang/dom": "1.1.1",
"elm-lang/html": "2.0.0",
"elm-lang/http": "1.0.0",
"debois/elm-dom": "1.2.3",
"elm-lang/window": "1.0.1",
"elm-lang/core": "5.1.1"
}
If you use the Lighttable editor with the elm-light plug in then you would have a command to show (and add) packages.