so what i am doing is that i am having 2 targets in a project, one is program for embedded device that i am crosscompiling, and the second are tests. I need to build them with 2 different compilers.
To main project i am passing arm compiler path by file toolchain.cmake and its working fine.
But right now i would like to build also the tests without having to add path to mingw64/bin to my environment variables (yes its working if i do that).
Test project is added as:
ExternalProject_Add(${UNIT_TEST_TARGET}
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/
PREFIX ${UNIT_TEST_TARGET}
CMAKE_ARGS ${GTEST_ARGS}
BUILD_ALWAYS TRUE
INSTALL_COMMAND cmake -E echo "Skipping install step."
EXCLUDE_FROM_ALL TRUE)
So right now i would like to pass to this external project file toolchaintests.cmake which looks like :
set(CMAKE_C_COMPILER <my_path_here>/mingw64/bin/gcc.exe)
set(CMAKE_CXX_COMPILER <my_path_here>/mingw64/bin/g++.exe)
with:
list(APPEND GTEST_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchaintests.cmake")
and if i do this cmake can't recognize the compilers:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: <my_path_here>/mingw64/bin/gcc.exe
-- Check for working C compiler: <my_path_here>/mingw64/bin/gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
" <my_path_here>/mingw64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: <my_path_here>/out/build/tests/src/tests-build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Ninja/ninja-win/ninja.exe cmTC_a1c48 && [1/2] Building C object CMakeFiles\cmTC_a1c48.dir\testCCompiler.c.obj
FAILED: CMakeFiles/cmTC_a1c48.dir/testCCompiler.c.obj
<my_path_here>\mingw64\bin\gcc.exe -o CMakeFiles\cmTC_a1c48.dir\testCCompiler.c.obj -c <my_path_here>\out\build\tests\src\tests-build\CMakeFiles\CMakeTmp\testCCompiler.c
ninja: build stopped: subcommand failed.
Can i do this somehow else?
Related
C++ development and related evironments are not something I use so I might be missing som knowledge in this area.
I want to do som sensor programming and want to deploy the example-project to get it working and then write my own code to extend it there after.
I've managed running projects in the Simulator using Visual Studio 2017.
But couldn't get building example-project using Visual Studio C++ Compiler working so installed MinGW firstly: https://sourceforge.net/projects/mingw/
But following the instructions at https://movesense.com/docs/esw/getting_started/#example-project
I can't run the create ninja files step correctly.
I get this error running the command:
cmake -G "Ninja" -DCMAKE_TOOLCHAIN_FILE=../movesense-device-lib/MovesenseCoreLib/toolchain/gcc-nrf52.cmake -DMOVESENSE_CORE_LIBRARY=../movesense-device-lib/MovesenseCoreLib ../ -DCMAKE_BUILD_TYPE=Debug ../
CMake Warning:
Ignoring extra path from command line:
"C:/Development/movesense-device-lib/MovesenseCoreLib/toolchain/gcc-nrf52.cmake"
CMake Warning:
Ignoring extra path from command line:
"../movesense-device-lib/MovesenseCoreLib"
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/MinGW/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/MinGW/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: C:/MinGW/bin/gcc.exe
CMake Error at CMakeLists.txt:13 (include):
include could not find requested file:
C:/Development/builddir//MovesenseFromStaticLib.cmake
Adding the MovesenseFromStaticLib.cmake manually doesn't work either gives me these errors:
Ignoring extra path from command line:
"C:/Development/movesense-device-lib/MovesenseCoreLib/toolchain/gcc-nrf52.cmake"
CMake Warning:
Ignoring extra path from command line:
"../movesense-device-lib/MovesenseCoreLib"
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/MinGW/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/MinGW/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: C:/MinGW/bin/gcc.exe
CMake Error at builddir/MovesenseFromStaticLib.cmake:29 (include):
include could not find requested file:
C:/Development/builddir/app-build/toolchain-setup.cmake
Call Stack (most recent call first):
CMakeLists.txt:13 (include)
CMake Error at builddir/MovesenseFromStaticLib.cmake:30 (include):
include could not find requested file:
C:/Development/builddir/app-build/prolog.cmake
Call Stack (most recent call first):
CMakeLists.txt:13 (include)
CMake Error at builddir/MovesenseFromStaticLib.cmake:32 (include):
include could not find requested file:
C:/Development/builddir/app-build/platform/.cmake
Call Stack (most recent call first):
CMakeLists.txt:13 (include)
CMake Error at builddir/MovesenseFromStaticLib.cmake:33 (include):
include could not find requested file:
C:/Development/builddir/app-build/compiler/.cmake
Call Stack (most recent call first):
CMakeLists.txt:13 (include)
CMake Error at builddir/MovesenseFromStaticLib.cmake:40 (INIT_SIMULATOR_ENVIRONMENT):
Unknown CMake command "INIT_SIMULATOR_ENVIRONMENT".
Call Stack (most recent call first):
CMakeLists.txt:13 (include)
-- Configuring incomplete, errors occurred!
Like Tsyvarev mentioned should be space after -D, but still get:
cmake -G "Ninja" -D CMAKE_TOOLCHAIN_FILE=../movesense-device-lib/MovesenseCoreLib/toolchain/gcc-nrf52.cmake -D MOVESENSE_CORE_LIBRARY=../movesense-device-lib/MovesenseCoreLib ../ -D CMAKE_BUILD_TYPE=Debug ../
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as
project(ProjectName)
near the top of the file, but after cmake_minimum_required().
CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error in CMakeLists.txt:
The CMAKE_C_COMPILER:
arm-none-eabi-gcc
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error in CMakeLists.txt:
The CMAKE_CXX_COMPILER:
arm-none-eabi-gcc
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
The CMakeLists.txt look like this:
cmake_minimum_required(VERSION 3.4)
enable_language(C CXX ASM)
if(NOT DEFINED MOVESENSE_CORE_LIBRARY)
# Give error that user must provide path to movescount-core library
message(FATAL_ERROR "Path to movesense-core library not set. Add -DMOVESENSE_CORE_LIBRARY=<path_to_core_lib> to cmake command line")
endif()
if(NOT IS_ABSOLUTE ${MOVESENSE_CORE_LIBRARY})
set(MOVESENSE_CORE_LIBRARY ${CMAKE_BINARY_DIR}/${MOVESENSE_CORE_LIBRARY})
endif()
include(${MOVESENSE_CORE_LIBRARY}/MovesenseFromStaticLib.cmake REQUIRED)
Any help on what is the issue and how to solve it?
You are trying to build the project on the MinGW terminal in windows instead of the Docker container as described in the documentation:
https://movesense.com/docs/esw/getting_started/#build-commands-real-hw
Starting Movesense 2.0 the docker environment is the only supported build environment.
Full disclosure: I work for the Movesense
I just started using CMake so I tried to build a simple hello-world project and got an error.
There is a main.cpp file, which contains this:
int main()
{
return 0;
}
And a CMakeLists.txt, which contains this:
cmake_minimum_required(VERSION "3.18.0")
project("test")
add_executable("${PROJECT_NAME}" "main.cpp")
install(TARGETS "${PROJECT_NAME}" DESTINATION bin)
install(FILES "main.cpp" DESTINATION src)
There also is a Build directory. I build the project from this directory with the following command:
cmake ..
What I eventually get is:
-- The C compiler identification is GNU 9.2.0
-- The CXX compiler identification is GNU 9.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe - broken
CMake Error at C:/CMake/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"C:/MinGW/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/PROGRA~2/GnuWin32/bin/make.exe cmTC_a48fd/fast && C:/PROGRA~2/GnuWin32/bin/make.exe -f CMakeFiles/cmTC_a48fd.dir/build.make CMakeFiles/cmTC_a48fd.dir/build
make.exe[1]: Entering directory `C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp'
The system cannot find the path specified.
make.exe[1]: *** [CMakeFiles/cmTC_a48fd.dir/testCCompiler.c.obj] Error 1
make.exe[1]: Leaving directory `C:/Projects/trash/checking_out_cmake/Build/CMakeFiles/CMakeTmp'
make.exe: *** [cmTC_a48fd/fast] Error 2
I have got CLion and it works just fine, so I presume this is MinGW compilers what causes the problem.
I have also tried to reinstall the compilers but the error remains.
Be sure not to use non-Latin characters in the absolute path to your working directory. In my case it was Cyrillic "C" as the name of folder.
I have a project here:
https://github.com/edhartnett/ncglm
It is a small C library for reading netCDF data files from the Geostationary Lightning Mapper. I have an autotools build which works fine, and I'm trying to add a CMake build.
The directory structure is simple, there is a main directory, a src directory, and a test directory.
In the main directory I have:
# This is the main cmake file for ncglm, a library to help read the
# netCDF data files from the Global Lightning Mapper (GLM) instrument
# on GOES-16 and GOES-17.
#
# Ed Hartnett 11/10/19
# This will use any cmake between 3.1 and 3.15, preferint later
# versions with updated policies.
cmake_minimum_required(VERSION 3.1...3.15)
if (${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
# set the project name
project(ncglm VERSION 1.0)
#Add custom CMake Module
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
CACHE INTERNAL "Location of our custom CMake modules.")
# Find netCDF.
include(FindNetCDF)
include_directories("${NETCDF_INCLUDES}")
# Create a config.h.
configure_file(config.h.cmake.in config.h)
# Turn on testing.
enable_testing()
include(CTest)
# Build in this subdirectory.
add_subdirectory(src test)
In the src subdirectory I have:
# This is the cmake file for the src directory of the ncglm library.
# Ed Hartnett 11/10/19
# Build the ncglm library.
add_library(ncglm glm_read.c goes_glm.h glm_data.h)
In the test directory I have:
# This is the cmake build file for the test directory of the ncglm library.
#
# Ed Hartnett 11/10/19
enable_testing()
add_test(NAME tst_glm_read COMMAND tst_glm_read)
build_test(tst_glm_read)
add_sh_test(nc_test4 run_glm_tests)
When I build, I get:
ed#mikado:~/ncglm/build$ cmake -DNETCDF_INCLUDES=/usr/local/netcdf-c-4.7.2_hdf5-1.10.5/include -DNETCDF_LIBRARIES=/usr/local/netcdf-c-4.7.2_hdf5-1.10.5/lib .. && make test
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found NetCDF: /usr/local/netcdf-c-4.7.2_hdf5-1.10.5/lib
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ed/ncglm/build
Running tests...
Test project /home/ed/ncglm/build
No tests were found!!!
How come cmake is not trying to build or run my test?
add_subdirectory(src test)
This is invalid / it doesn't do what you think it does. What you want to do is:
add_subdirectory(src)
add_subdirectory(test)
The cmake website is down right now, I can't link to it. From memory the add_subdirectory(src test) reads CMakeLists.txt in the src source directory, but builds the sources in the test build directory, the test is created inside the build directory inside CMAKE_CURRENT_BUILD_DIR. To add two source directories, you have to use two add_subdirectory().
I am trying to setup cmake using Windows 10 using MinGW. I have included the path c:/MinGW/bin in my system path and environment path settings. I have removed sh.exe from my path (although, i would love to be able to keep this if possible).
CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/gcc.exe")
project (Tutorial)
add_executable(Tutorial tutorial.cpp)
Output
C:\School\athabascua\data structures\ass1>cmake -g "MinGW Makefiles" .
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_b3144\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: C:/School/athabascua/data structures/ass1/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_b3144\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_b3144\fast"
It seems that the GNU compilers are identified but don't seem to work. Any help would be much appreciated. I am trying to avoid using Cygwin.. but almost ready to go that route in a sec here.
To fix the problem I was having, I had to do two things.
use the command cmake -G "MinGW Makefiles" . (capital -G on windows)
update my CMakeLists.txt file to use gcc for C compiler and g++ for C++ compiler
CMakeLists.txt
cmake_minimum_required(VERSION 3.8)
set(CMAKE_C_COMPILER "C:/MinGW/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/MinGW/bin/g++.exe")
project (Tutorial)
add_executable(Tutorial tutorial.cpp)
I have the following compile time error I cannot find the reason of:
fatal error: mysql_connection.h: No such file or directory
I am using cmake, and these are the CMakeLists.txt files:
# Top level CMakeLists.txt - MyProg
cmake_minimum_required (VERSION 2.6)
set (PROJECT_NAME "MyProg")
### Out-of-tree directories
set (UTILITIES_DIR "~/utilities")
### Configure header file to pass CMake's settings to the source code
configure_file (
"Config.h.in"
"${PROJECT_SOURCE_DIR}/Config.h"
)
add_subdirectory (src "${CMAKE_CURRENT_BINARY_DIR}/obj")
add_subdirectory (${UTILITIES_DIR} "${CMAKE_CURRENT_BINARY_DIR}/obj/external/utilities")
and
# Source level CMakeLists.txt - MyProg/src
### MySQL Connector/C++ ###
set (MYSQLCONNECTORCPP_ROOT_DIR "~/3rdParty/mysql-connector-c++-1.1.0")
### Include paths ###
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
include_directories (${UTILITIES_DIR})
include_directories (${MYSQLCONNECTORCPP_ROOT_DIR})
include_directories (/usr/local/include)
link_directories (/usr/local/lib)
link_directories (${MYSQLCONNECTORCPP_ROOT_DIR}/driver)
link_directories (/usr/lib64/mysql/)
link_directories (/usr/lib64/)
link_directories (/usr/local/mysql/lib/)
add_executable (myprog
entrypoint.cpp
MyProg.cpp
MyProg_test.cpp
${UTILITIES_DIR}/DBInterface.cpp
)
target_link_libraries (myprog mysqlcppconn-static mysqlclient)
This is the output from cmake (out of source build):
> cmake ../MyProg/
-- The C compiler identification is GNU 4.7.1
-- The CXX compiler identification is GNU 4.7.1
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: ~/MyProg_prj/Debug
And this is the fatal error I get from make:
> make
Scanning dependencies of target myprog
[ 8%] Building CXX object obj/CMakeFiles/myprog.dir/entrypoint.cpp.o
In file included from ~/MyProg_prj/MyProg/src/entrypoint.cpp:18:0:
~/utilities/DBInterface.hpp:18:30: fatal error: mysql_connection.h: No such file or directory
compilation terminated.
make[2]: *** [obj/CMakeFiles/myprog.dir/entrypoint.cpp.o] Error 1
make[1]: *** [obj/CMakeFiles/myprog.dir/all] Error 2
make: *** [all] Error 2
The mysql_connection.h file is in the directory specified in the CMakeLists.txt file.
This problem happened after I upgraded Linux (before it worked correctly), but this should not be the reason. The PATH should contain everything needed.
Thank you.
Platform: Linux (OpenSuse), GCC 4.7.1, cmake, MySQL Connector C++ 1.1.0
You are most likely missing the 'libmysqlcppconn-dev' library. Once installed, you shouldn't be seeing this error.
Before updating the system, in the source code I included the MySQL header like this:
#include <mysql_connection.h>
Now I have to specify the subdirectory:
#include <driver/mysql_connection.h>
Something must have changed in how the paths are set...