# Is CMAKE\_FIND\_ROOT\_PATH will overwrite the default search path of compiler?

**URL:** https://discourse.cmake.org/t/is-cmake-find-root-path-will-overwrite-the-default-search-path-of-compiler/9553
**Category:** Usage
**Created:** [December 4, 2023, 3:47pm UTC](https://discourse.cmake.org/t/is-cmake-find-root-path-will-overwrite-the-default-search-path-of-compiler/9553 "2023-12-04T15:47:59Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ricky\_Yel](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ricky_yel/32/4053_2.png) [@Ricky\_Yel](https://discourse.cmake.org/u/Ricky_Yel)
#### Post date: [December 4, 2023, 3:47pm UTC](https://discourse.cmake.org/t/is-cmake-find-root-path-will-overwrite-the-default-search-path-of-compiler/9553/1 "2023-12-04T15:47:59Z")

</div>

ubuntu 22.04 and gcc9.4.0

After type the command: `echo | gcc -Wp,-v -x c++ - -fsyntax-only`

it will output:

ignoring duplicate directory “/usr/include/x86\_64-linux-gnu/c++/9”  
ignoring nonexistent directory “/usr/local/include/x86\_64-linux-gnu”  
ignoring nonexistent directory “/usr/lib/gcc/x86\_64-linux-gnu/9/include-fixed”  
ignoring nonexistent directory “/usr/lib/gcc/x86\_64-linux-gnu/9/…/…/…/…/x86\_64-linux-gnu/include”  
#include “…” search starts here:  
#include \<…\> search starts here:  
/usr/include/c++/9  
/usr/include/x86\_64-linux-gnu/c++/9  
/usr/include/c++/9/backward  
/usr/lib/gcc/x86\_64-linux-gnu/9/include  
/usr/local/include  
/usr/include/x86\_64-linux-gnu  
/usr/include  
End of search list.

I want to know if setting `ONLY_CMAKE_FIND_ROOT_PATH ` will override the compiler’s default search paths？

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 6, 2023, 12:52pm UTC](https://discourse.cmake.org/t/is-cmake-find-root-path-will-overwrite-the-default-search-path-of-compiler/9553/2 "2023-12-06T12:52:06Z")

</div>

Are you asking whether the `ONLY_CMAKE_FIND_ROOT_PATH` will cause CMake to pass a flag to the compiler to drop default search paths when compiling? If that is the question, I don’t think so. Other than that, I’m not sure what `find_*` command control variables have to do with default compiler search paths.

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![Ricky\_Yel](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ricky_yel/32/4053_2.png) [@Ricky\_Yel](https://discourse.cmake.org/u/Ricky_Yel)
#### Post date: [December 6, 2023, 2:50pm UTC](https://discourse.cmake.org/t/is-cmake-find-root-path-will-overwrite-the-default-search-path-of-compiler/9553/3 "2023-12-06T14:50:18Z")

</div>

Thank you very much for your reply, and I apologize for causing confusion. Allow me to provide a specific description of my question:

When using the following CMake variables:

```cmake
# where is the target environment located
set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc
    /home/alex/mingw-install)

# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

```

For gcc or g++ or ld, will it override their default paths for searching header files or library files? I believe this is important for cross-compilation scenarios.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [December 11, 2023, 1:27pm UTC](https://discourse.cmake.org/t/is-cmake-find-root-path-will-overwrite-the-default-search-path-of-compiler/9553/4 "2023-12-11T13:27:36Z")

</div>

If I understand your question correctly, no. These variables do nothing to set up include paths to find the files. I suspect that the toolchain file needs to provide the setup for this itself (as projects shouldn’t have to guess at cross-compile setups on their own).

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [December 13, 2023, 11:15pm UTC](https://discourse.cmake.org/t/is-cmake-find-root-path-will-overwrite-the-default-search-path-of-compiler/9553/5 "2023-12-13T23:15:01Z")

</div>

Your code snippet has some “mingw” references:  
You have to configure CMake to use the mingw compiler executables. In general cross-compilation is not done with your host compiler.
