Compiler flags lost when cross-compiling

Hello,

I am trying to cross-compile Ceres-solver for an ARM system. I have created a toolchain file with settings based on a known, working configuration.

When I try to cross-compile Ceres-solver using my toolchain:cmake -DCMAKE_TOOLCHAIN_FILE=../ceres-solver-2.2.0/cmake/toolchain.cmake ../ceres-solver-2.2.0

The build fails with errors like:

path/to/compiler/ld: cannot find -lstdc++

These types of errors are the ones you would see by calling the compiler without any flags. My toolchain file has CMAKE_CXX_COMPILER and CMAKE_CXX_FLAGS defined and these are carried over to the CMakeLists.txt from Ceres-solver.

As far as I am aware, CMAKE_CXX_FLAGS is never overwritten.

Interestingly, the CMakeOutput.log file (which seems to identify the compiler and run some checks) shows that CMake does use the CMAKE_CXX_FLAGS correctly and cross-compiles small test executables that work.

Is there any reason why CMake would not use CMAKE_CXX_FLAGS when cross-compiling?

Regards,
R.J.

I managed to fix the issue myself. It turns out that I did not wrap the flags I passed to CMAKE_CXX_FLAGS in quotes.

Instead of set(CMAKE_CXX_FLAGS "--flag1 --flag2"), I had set(CMAKE_CXX_FLAGS --flag1 --flag2).

Without the quotes, CMake turned the flags into a semicolon-separated list of commands.