# How to use CMake to cross-compile for Linux target using Wind River cross-compiler?

**URL:** https://discourse.cmake.org/t/how-to-use-cmake-to-cross-compile-for-linux-target-using-wind-river-cross-compiler/580
**Category:** Usage
**Created:** [February 5, 2020, 10:26am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-cross-compile-for-linux-target-using-wind-river-cross-compiler/580 "2020-02-05T10:26:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [February 5, 2020, 10:26am UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-cross-compile-for-linux-target-using-wind-river-cross-compiler/580/1 "2020-02-05T10:26:55Z")

</div>

We develop an application that runs on Intel processor under Linux using a Wind River toolset. The application is built on Windows using an Eclipse-based IDE, CDT and gnu make, using the Wind River cross-compiler. I want to replace this arrangement with CMake, running on Windows.

I can invoke the cross-compiler from Windows cmd prompt. Neither Cygwin nor MinGW seem to be required (though I may have understood). In my CMakeLists.txt file I specify the compiler:

```
set(TOOL_PATH "C:/Leda_sdk/sysroots/x86_64-wrlinuxsdk-mingw32/usr/bin/x86_64-wrs-linux/")
set(CROSS_COMPILE "x86_64-wrs-linux-")
set(CMAKE_C_COMPILER ${TOOL_PATH}${CROSS_COMPILE}gcc.exe)
set(CMAKE_CXX_COMPILER ${TOOL_PATH}${CROSS_COMPILE}g++.exe)

```

When I run CMake:

```
cmake -G Ninja ..

```

The test compile fails:

```
Run Build Command(s):C:/bin/ninja-win/ninja.exe cmTC_d497e
[1/2] Building CXX object CMakeFiles/cmTC_d497e.dir/testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_d497e.exe
FAILED: cmTC_d497e.exe
cmd.exe /C "cd . && C:\Leda_sdk\sysroots\x86_64-wrlinuxsdk-mingw32\usr\bin\x86_64-wrs-linux\x86_64-wrs-linux-g++.exe CMakeFiles/cmTC_d497e.dir/testCXXCompiler.cxx.obj -o cmTC_d497e.exe -Wl,--out-implib,libcmTC_d497e.dll.a -Wl,--major-image-version,0,--minor-image-version,0 && cd ."
c:/leda_sdk/sysroots/x86_64-wrlinuxsdk-mingw32/usr/bin/x86_64-wrs-linux/../../libexec/x86_64-wrs-linux/gcc/x86_64-wrs-linux/5.2.0/real-ld.exe: unrecognized option '--out-implib'

```

I am guessing that this is because CMake is invoking a toolchain that uses MinGW. Am I correct?

How would I fix this please?

Best regards  
David

---

<div class="post-metadata">

### Author: ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)
#### Post date: [February 5, 2020, 1:13pm UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-cross-compile-for-linux-target-using-wind-river-cross-compiler/580/2 "2020-02-05T13:13:46Z")

</div>

It sounds like you want to write a [toolchain file](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html). Setting the C/C++ compiler from inside `CMakeLists.txt` won’t work - it has to be set from the command line or from the toolchain file.

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [February 5, 2020, 3:18pm UTC](https://discourse.cmake.org/t/how-to-use-cmake-to-cross-compile-for-linux-target-using-wind-river-cross-compiler/580/3 "2020-02-05T15:18:24Z")

</div>

Thanks for your answer. I have added a toolchain and it is working ok.
