# Compiler flags lost when cross-compiling

**URL:** https://discourse.cmake.org/t/compiler-flags-lost-when-cross-compiling/15360
**Category:** Usage
**Created:** [December 3, 2025, 12:13am UTC](https://discourse.cmake.org/t/compiler-flags-lost-when-cross-compiling/15360 "2025-12-03T00:13:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![bobjohnson](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/34f0e0/32.png) [@bobjohnson](https://discourse.cmake.org/u/bobjohnson)
#### Post date: [December 3, 2025, 12:13am UTC](https://discourse.cmake.org/t/compiler-flags-lost-when-cross-compiling/15360/1 "2025-12-03T00:13:06Z")

</div>

Hello,

I am trying to cross-compile [Ceres-solver](http://ceres-solver.org/) 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.

---

<div class="post-metadata">

### Author: ![bobjohnson](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/34f0e0/32.png) [@bobjohnson](https://discourse.cmake.org/u/bobjohnson)
#### Post date: [December 3, 2025, 9:48pm UTC](https://discourse.cmake.org/t/compiler-flags-lost-when-cross-compiling/15360/2 "2025-12-03T21:48:09Z")

</div>

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.
