# How can I use CMake with GreenHills compiler

**URL:** https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388
**Category:** Usage
**Tags:** os:windows, gen:makefiles
**Created:** [November 1, 2021, 12:34pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388 "2021-11-01T12:34:37Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![AbdAllah.ElTamaly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@AbdAllah.ElTamaly](https://discourse.cmake.org/u/AbdAllah.ElTamaly)
#### Post date: [November 1, 2021, 12:34pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/1 "2021-11-01T12:34:37Z")

</div>

Hello,

I have been trying to use CMake to generate Makefiles for a C project compiling using GreenHills compiler. But I am getting these errors:

– The C compiler identification is GHS  
– The CXX compiler identification is GHS  
– Detecting C compiler ABI info  
CMake Error: Generator: execution of make failed. Make command was: C:/AGL\_2005/COMPILER/ARM/GHS/V2019\_5\_4/ccarm.exe/gbuild.exe -top CMAKE\_TRY\_COMPILE.top.gpj cmTC\_dd868.tgt.gpj &&  
– Detecting C compiler ABI info - failed  
– Check for working C compiler: C:/AGL\_2005/COMPILER/ARM/GHS/V2019\_5\_4/ccarm.exe  
CMake Error: Generator: execution of make failed. Make command was: C:/AGL\_2005/COMPILER/ARM/GHS/V2019\_5\_4/ccarm.exe/gbuild.exe -top CMAKE\_TRY\_COMPILE.top.gpj cmTC\_86df9.tgt.gpj &&  
– Check for working C compiler: C:/AGL\_2005/COMPILER/ARM/GHS/V2019\_5\_4/ccarm.exe - broken  
CMake Error at C:/Sources/cmake-3.21.3-windows-x86\_64/share/cmake-3.21/Modules/CMakeTestCCompiler.cmake:69 (message):  
The C compiler

```
"C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe"

```

is not able to compile a simple test program.

It fails with the following output:

```
Change Dir: C:/UIDE/build/CMakeFiles/CMakeTmp

Run Build Command(s):C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe/gbuild.exe -top CMAKE_TRY_COMPILE.top.gpj cmTC_86df9.tgt.gpj && The system cannot find the file specified
Generator: execution of make failed. Make command was: C:/AGL_2005/COMPILER/ARM/GHS/V2019_5_4/ccarm.exe/gbuild.exe -top CMAKE_TRY_COMPILE.top.gpj cmTC_86df9.tgt.gpj &&

```

CMake will not be able to correctly generate this project.  
Call Stack (most recent call first):  
CMakeLists.txt:3 (project)

– Configuring incomplete, errors occurred!  
See also “C:/UIDE/build/CMakeFiles/CMakeOutput.log”.  
See also “C:/UIDE/build/CMakeFiles/CMakeError.log”.

Could you please help?

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 1, 2021, 9:00pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/2 "2021-11-01T21:00:48Z")

</div>

What was the full command to CMake to receive this output?

I’m confused why the output shows `gbuild.exe`. This is the build tool for GHS project files which is a file format very different from Makefiles. You can use GHS compilers with Ninja or Make but then you need to run the appropriate generator and use the correct compiler options.

CMake can also be used to generate GHS project files for use with MULTI and `gbuild.exe`.  
In this case the command line would be something like: `cmake -G "Green Hills MULTI" -T "C:\AGL_2005\COMPILER\ARM\GHS\V2019_5_4" -D GHS_PRIMARY_TARGET=arm_standalone.tgt`. `ccarm` should be the standalone target compiler for ARM. `-T` is used to specify the directory of where the tools are installed. I made a guess on what target you wanted for `GHS_PRIMARY_TARGET`. This is usually specific to the board you are targeting and should have been specified when receiving the tools from Green Hills.

---

<div class="post-metadata">

### Author: ![AbdAllah.ElTamaly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@AbdAllah.ElTamaly](https://discourse.cmake.org/u/AbdAllah.ElTamaly)
#### Post date: [November 2, 2021, 12:46pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/3 "2021-11-02T12:46:54Z")

</div>

@fdk17 Thank you so much Your input is very helpful.

Now it is generated but with another error in the linker

Green Hills MULTI: -A not specified; defaulting to “arm”  
– The C compiler identification is GHS 2019.5.4  
– The CXX compiler identification is GHS 2019.5.4  
– Detecting C compiler ABI info  
– Detecting C compiler ABI info - done  
– Check for working C compiler: C:/AGL\_2005/COMPILER/ARM/GHS/V2019\_5\_4/ccarm.exe - skipped  
– Detecting CXX compiler ABI info  
– Detecting CXX compiler ABI info - done  
– Check for working CXX compiler: C:/AGL\_2005/COMPILER/ARM/GHS/V2019\_5\_4/cxarm.exe - skipped  
– Configuring done  
CMake Error: CMake can not determine linker language for target: UIDE\_test\_1.elf  
CMake Error: CMake can not determine linker language for target: UIDE\_test\_1.elf  
– Generating done  
CMake Generate step failed. Build files cannot be regenerated correctly.

Do you have any suggestion for that?

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 2, 2021, 1:57pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/4 "2021-11-02T13:57:15Z")

</div>

> [@AbdAllah.ElTamaly](#):
>
> CMake Error: CMake can not determine linker language for target: UIDE\_test\_1.elf

Sorry, I’ve never seen such an error.

---

<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: [November 2, 2021, 4:32pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/5 "2021-11-02T16:32:18Z")

</div>

Have you added at least one C/C++ file to your executable?

---

<div class="post-metadata">

### Author: ![AbdAllah.ElTamaly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@AbdAllah.ElTamaly](https://discourse.cmake.org/u/AbdAllah.ElTamaly)
#### Post date: [November 3, 2021, 10:00am UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/6 "2021-11-03T10:00:20Z")

</div>

@jtxa Yes

---

<div class="post-metadata">

### Author: ![AbdAllah.ElTamaly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@AbdAllah.ElTamaly](https://discourse.cmake.org/u/AbdAllah.ElTamaly)
#### Post date: [November 3, 2021, 10:01am UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/7 "2021-11-03T10:01:39Z")

</div>

I solved the problem of this error:  
CMake Error: CMake can not determine linker language for target: UIDE\_test\_1.elf

by adding the following line after the line of “add\_executable”  
set\_target\_properties(${PROJECT\_NAME} PROPERTIES LINKER\_LANGUAGE CXX)

---

<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: [November 4, 2021, 9:35pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/8 "2021-11-04T21:35:19Z")

</div>

This is usually only necessary, if you don’t have any recognized source files.  
So if you have added e.g. a `main.cpp` to your executable, the language should be automatically set to `CXX`.

---

<div class="post-metadata">

### Author: ![AbdAllah.ElTamaly](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@AbdAllah.ElTamaly](https://discourse.cmake.org/u/AbdAllah.ElTamaly)
#### Post date: [November 7, 2021, 9:04am UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/9 "2021-11-07T09:04:29Z")

</div>

@jtxa  
This is confusing!  
Because I have already added a main.c file.  
Do you think the file couldn’t be read properly?

---

<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: [November 7, 2021, 2:15pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/10 "2021-11-07T14:15:41Z")

</div>

I don’t know if there are some issues with GHS generator (which I don’t have) or your cmake files.  
I made a minimal example to demonstrate it. With `if(1)` it shows the “_can not determine linker language for target_” error message. And with `if(0)` the message vanishes.

```auto
cmake_minimum_required(VERSION 3.13)
project(x LANGUAGES C)
add_executable(x)

if(1)
  target_sources(x PRIVATE "${CMAKE_BINARY_DIR}/main.unknown")
  file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/main.unknown" CONTENT "")
else()
  target_sources(x PRIVATE "${CMAKE_BINARY_DIR}/main.c")
  file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/main.c" CONTENT "")
endif()

```

For this error message the content of `main.c` is irrelevant, because CMake only uses the file extension to decide the language.

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 7, 2021, 2:45pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/11 "2021-11-07T14:45:24Z")

</div>

> [@AbdAllah.ElTamaly](#):
>
> CMake can not determine linker language for target

I haven’t run into that issue with C and CXX code while using the GHS generator. If you could create a minimum example that demonstrates the issue that would be beneficial to understanding the problem.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [November 7, 2021, 8:19pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/12 "2021-11-07T20:19:55Z")

</div>

Do you have a `toolchain` file for the **GHS** tools?

see too [cmake/cmake#19743](https://gitlab.kitware.com/cmake/cmake/-/issues/19743)

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [November 8, 2021, 12:48am UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/13 "2021-11-08T00:48:24Z")

</div>

@ClausKlein No,  
I haven’t found it necessary to use one. I do use a small script to run the CMake command. For me it’s working fine. I’m using the `Green Hills MULTI` generator to use `gbuild` to parse the integrate file, generate header files, build the kernel, build the applications, and then integrate everything into a Monolith image, then a custom command to deploy image.

I’m not using `Ninja` for running the build with the GHS compilers. I pushed some changes that incorporates some of the ideas of #19743. cmake/cmake!4136 and cmake/cmake#20089 make it easy to at least compile a file with Ninja but there would be more work for archiving libraries. Then there would be the custom rules for running the `integrate` and other commands required for building a monolith image.

---

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [November 8, 2021, 12:39pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/14 "2021-11-08T12:39:22Z")

</div>

I work with Ninja and this toolchain:

```cmake
# Toolchain file for Green Hills Software MULTI environment for Integrity target 
#
# Requires environment variables MULTI_ROOT, INTEGRITY_BASE, and INTEGRITY_BSP
# set to the right directories of the Integrity/PPC environment

set(CMAKE_SYSTEM_NAME GHS-MULTI)
set(CMAKE_SYSTEM_PROCESSOR ppc)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_CXX_PLATFORM_ID Integrity)

# Disable Compiler tests
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_C_COMPILER_ID_RUN 1)
set(CMAKE_C_ABI_COMPILED 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_ID_RUN 1)
set(CMAKE_CXX_ABI_COMPILED 1)

# Get MULTI root path from environment
file(TO_CMAKE_PATH $ENV{MULTI_ROOT} MULTI_ROOT)
message(STATUS "MULTI_ROOT: ${MULTI_ROOT}")

# Set default cmake flags variables
set(CMAKE_C_FLAGS "-os_dir=$ENV{INTEGRITY_BASE} -bsp=$ENV{INTEGRITY_BSP}")
set(CMAKE_CXX_FLAGS "-os_dir=$ENV{INTEGRITY_BASE} -bsp=$ENV{INTEGRITY_BSP}")
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

# Set compilers
set(CMAKE_C_COMPILER ${MULTI_ROOT}/ccintppc.exe)
set(CMAKE_CXX_COMPILER ${MULTI_ROOT}/ccintppc.exe)

# Set compilers ID
set(CMAKE_C_COMPILER_ID "GHS")
set(CMAKE_CXX_COMPILER_ID "GHS")

set(CMAKE_C_STANDARD_COMPUTED_DEFAULT 99)
set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT 98)

# Set format for compiling
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -MD -filetype.c <SOURCE> -o <OBJECT>") 
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -MD -filetype.cc <SOURCE> -o <OBJECT>")
# TODO: --instantiation_dir=<OBJECT>_") 

# Set format for creating static library
set(CMAKE_CXX_CREATE_STATIC_LIBRARY "${MULTI_ROOT}/cxintppc.exe <LINK_FLAGS> -o <TARGET> <OBJECTS> -keep_objs")
set(CMAKE_C_CREATE_STATIC_LIBRARY "${MULTI_ROOT}/cxintppc.exe <LINK_FLAGS> -o <TARGET> <OBJECTS> -keep_objs")

# Set format to create executables
set(CMAKE_CXX_LINK_EXECUTABLE "${MULTI_ROOT}/cxintppc.exe <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
set(CMAKE_C_LINK_EXECUTABLE "${MULTI_ROOT}/cxintppc.exe <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")

set(CMAKE_FIND_ROOT_PATH ${MULTI_ROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

```

---

<div class="post-metadata">

### Author: ![Vinoth\_Rani](https://discourse.cmake.org/user_avatar/discourse.cmake.org/vinoth_rani/32/2038_2.png) [@Vinoth\_Rani](https://discourse.cmake.org/u/Vinoth_Rani)
#### Post date: [December 15, 2021, 8:25pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/15 "2021-12-15T20:25:53Z")

</div>

How can i compile a Assembly file using GHS compile rtoolchain with CMAKE. I tried with setting up target properties as ASM but no luck,

I also have below in my topl level CMAKE list.

enable\_language(ASM)  
enable\_language(C)  
enable\_language(CXX)

Can some one help me on this. I noticed below  
– Warning: Did not find file Compiler/GHS-ASM  
– Warning: Did not find file Compiler/GHS-ASM  
– Configuring done

---

<div class="post-metadata">

### Author: ![payneshouse](https://discourse.cmake.org/user_avatar/discourse.cmake.org/payneshouse/32/4632_2.png) [@payneshouse](https://discourse.cmake.org/u/payneshouse)
#### Post date: [June 3, 2024, 6:23pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/17 "2024-06-03T18:23:49Z")

</div>

> [@fdk17](#):
>
> I haven’t found it necessary to use one. I do use a small script to run the CMake command. For me it’s working fine. I’m using the `Green Hills MULTI` generator to use `gbuild` to parse the integrate file, generate header files, build the kernel, build the applications, and then integrate everything into a Monolith image, then a custom command to deploy image.
> 
> I’m not using `Ninja` for running the build with the GHS compilers. I pushed some changes that incorporates some of the ideas of #19743. cmake/cmake!4136 and cmake/cmake#20089 make it easy to at least compile a file with Ninja but there would be more work for archiving libraries. Then there would be the custom rules for running the `integrate` and other commands required for building a monolith image.

Hi fdk17,

I came across your post about using the Green Hills MULTI generator with CMake and had a quick question. I apologize for responding to an old message, but I’m really interested in your approach.

You mentioned that you use the Green Hills MULTI generator to parse the integrate file, generate header files, build the kernel, build the applications, and integrate everything into a Monolith image. Did you manage to do all this natively with the CMake Green Hills MULTI generator, or did you have to add custom commands to achieve this?

I’m currently trying to create a CMake build that uses the Green Hills MULTI generator, but I’m struggling to get it to actually create a Green Hills project that builds a Monolith image. Any insights or guidance would be greatly appreciated!

Thanks,  
payneshouse

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [June 4, 2024, 6:58pm UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/18 "2024-06-04T18:58:34Z")

</div>

> [@payneshouse](#):
>
> Did you manage to do all this natively with the CMake Green Hills MULTI generator, or did you have to add custom commands to achieve this?

Many of the build steps are performed via `add_custom_target` and `add_custom_command`.

---

<div class="post-metadata">

### Author: ![wild.boy](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/w/fbc32d/32.png) [@wild.boy](https://discourse.cmake.org/u/wild.boy)
#### Post date: [January 22, 2025, 6:51am UTC](https://discourse.cmake.org/t/how-can-i-use-cmake-with-greenhills-compiler/4388/19 "2025-01-22T06:51:19Z")

</div>

I encountered a problem when compiling C code using the Ghs compiler through CMake.  
Scenario: The MinGw Makefiles generator is used.  
Problem: When compiling the source file, I always get a warning that “init.c.obj ignored with these options”, where init.c is the source file. Could it be that the ghs compiler does not recognize the.obj format of the output file? However, even after performing the following operations:  
cmake：  
SET(CMAKE\_C\_OUTPUT\_EXTENSION.o)  
SET(CMAKE\_CXX\_OUTPUT\_EXTENSION.o)  
SET(CMAKE\_ASM\_OUTPUT\_EXTENSION.o)  
I am still unable to set the output file to a.o file. Do you have any good solutions to this warning?
