Need to change GCC compiler and path for a subproject

I need to change the name and path of a GCC compiler. I am using a real-time compiler from National Instruments, a GCC clone. I have found a way to force a new path with

plugins {
    id 'cpp-library'
}

library {    
	linkage = [Linkage.STATIC]

	targetMachines.add(machines.windows.x86_64)
	targetMachines.add(machines.linux.x86_64)

	model {
		toolChains {
			gcc(Gcc) {
				path 'C:\\Users\\....\\CRIOCompiler23Q4\\oecore-x86_64-core2-64-toolchain\\sysroots\\x86_64-w64-mingw32\\usr\\bin\\x86_64-nilrt-linux'
			}
		}
	}
}

I get the following error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task 'compileDebugCpp'.
> Error while evaluating property 'compilerVersion' of task 'compileDebugCpp'.
   > No tool chain is available to build C++ for host operating system 'Windows 10' architecture 'x86-64':
       - Tool chain 'gcc' (GNU GCC):
           - Could not find C++ compiler 'g++'. Searched in:
               - C:\Users\n24090\CRIOCompiler23Q4\oecore-x86_64-core2-64-toolchain\sysroots\x86_64-w64-mingw32\usr\bin\x86_64-nilrt-linux

Now I need to change the name of the compiler from ‘g++’ to ‘x86_64-nilrt-linux-g++.exe’. I have tried

plugins {
    id 'cpp-library'
}

library {
	linkage = [Linkage.STATIC]
	
	targetMachines.add(machines.windows.x86_64)

	model {
		toolChains {
			gcc(Gcc) {
				path 'C:\\Users\\n24090\\CRIOCompiler23Q4\\oecore-x86_64-core2-64-toolchain\\sysroots\\x86_64-w64-mingw32\\usr\\bin\\x86_64-nilrt-linux'
				cCompiler.executable 'x86_64-nilrt-linux-gcc.exe'
				cppCompiler.executable 'x86_64-nilrt-linux-g++.exe'
				assembler.executable 'x86_64-nilrt-linux-as.exe'
                linker.executable 'x86_64-nilrt-linux-ld.exe'
			}
		}
	}
}

Which returns the following error

FAILURE: Build failed with an exception.

* Where:
Build file 'build.gradle' line: ...

* What went wrong:
A problem occurred configuring project '...'.
> Failed to notify project evaluation listener.
   > Exception thrown while executing model rule: model.toolChains
      > Could not get unknown property 'cCompiler' for Tool chain 'gcc' (GNU GCC) of type org.gradle.nativeplatform.toolchain.internal.gcc.GccToolChain.
   > Exception thrown while executing model rule: model.toolChains
      > Could not get unknown property 'cCompiler' for Tool chain 'gcc' (GNU GCC) of type org.gradle.nativeplatform.toolchain.internal.gcc.GccToolChain.

I am hoping this is a relatively simple change.

Thanks for any help.

It is, those tool settings are not on Gcc, but nested in eachPlatform { ... } or target(...) { ... }. :slight_smile:

Is it

target (machines.windows.x86_64) { ...}

When I used ‘machines.windows.x86_64’ in target, it seemed to give me an error. I am not at the computer so I cannot test.

https://docs.gradle.org/current/userguide/native_software.html#example_defining_target_platforms

Thanks for the help!!

1 Like

I was way over complicating this. It very easy once I saw past my own preconception.

plugins {
    id 'cpp-application' // or 'cpp-library'
}

application {
    model {
        toolChains {
            gcc(Gcc) {
                path 'C:\\CRIOCompiler23Q4\\oecore-x86_64-core2-64-toolchain\\sysroots\\x86_64-w64-mingw32\\usr\\bin\\x86_64-nilrt-linux'
                eachPlatform {
                    cCompiler.executable 'x86_64-nilrt-linux-gcc.exe'
                    cppCompiler.executable 'x86_64-nilrt-linux-g++.exe'
                }
            }
        }
    }
}
> Configure project :
Evaluating root project 'CRIO' using build file 'X:\workspace\cRIOsRefactor\CRIO\build.gradle'.
Starting process 'command 'C:\CRIOCompiler23Q4\oecore-x86_64-core2-64-toolchain\sysroots\x86_64-w64-mingw32\usr\bin\x86_64-nilrt-linux\x86_64-nilrt-linux-gcc.exe''. Working directory: C:\CRIOCompiler23Q4\oecore-x86_64-core2-64-toolchain\sysroots\x86_64-w64-mingw32\usr\bin\x86_64-nilrt-linux Command: C:\CRIOCompiler23Q4\oecore-x86_64-core2-64-toolchain\sysroots\x86_64-w64-mingw32\usr\bin\x86_64-nilrt-linux\x86_64-nilrt-linux-gcc.exe -m64 -dM -E -v -
Successfully started process 'command 'C:\CRIOCompiler23Q4\oecore-x86_64-core2-64-toolchain\sysroots\x86_64-w64-mingw32\usr\bin\x86_64-nilrt-linux\x86_64-nilrt-linux-gcc.exe''
All projects evaluated.
1 Like