Gradle c plugin on Linux, how to insert compiler options?

(Michael Shulman) #1

On Linux, using Gradle, I’m trying to build a C static library using the C plugin. It fails with compiler error messages. But I can build the static library successfully using an existing batch/make file. I assume I need to add compiler flags to my build.gradle, but I don’t know how, and can’t find documentation for it.

Here’s a summary of my problem:
On Linux, when I use Gradle to build a static library, I get compiler errors
concerning C-style “far” pointers. But if I build using well-developed batch/make
files, it compiles and links successfully.

Let’s say my project directory is /home/me/mylib
In that library, I have that looks like this:

apply plugin: ‘c’

model {

components {
	mylib(NativeLibrarySpec) {
		sources {
			c {
				source {
					srcDirs "src"
					include "*.c"
				exportedHeaders {
					srcDir "inc"


I type:
./gradlew build

I get error messages, all involving *far pointers. A typical bad line
looks like this:

int far *pSomething;

with an error message in output.txt like this:

myHdr.h:21: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token

There’s an options.txt file, apparently generated automatically,
which looks like this:


If I try to use the good-old batch file, it works, with this message:

/usr/bin/gcc -I. -I/home/me/mylib/inc -DUNIX -DRS6000
-DIBMRS6000 -DNDEBUG -c -fPIC -m64 -dalign -DDS_64BIT -O0
-o /home/me/mylib/obj/myfile.o
-c /home/me/mylib/src/myfile.c

I assume that this successful compile line tells me what options I need
to use, and I should encorporate these options into my But
I have no idea which of these options need to be inserted. (Maybe all?)

And I have no idea what syntax to use in to put in these

Any help would be appreciated!

(Michael Shulman) #2

OK, I found the documentation online and fixed the problem. In my build.gradle, I now add the following:

binaries {
	all {
		cCompiler.define "UNIX"
		cCompiler.define "RS6000"
		cCompiler.define "IBMRS6000"
		cCompiler.define "NDEBUG"
		cCompiler.define "DS_64BIT"
		cCompiler.args '-c', '-fPIC', '-m64', '-dalign', '-O0'