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

**URL:** <https://discuss.gradle.org/t/gradle-c-plugin-on-linux-how-to-insert-compiler-options/27808>\
**Category:** Help/Discuss\
**Created:** [July 19, 2018, 2:21pm UTC](https://discuss.gradle.org/t/gradle-c-plugin-on-linux-how-to-insert-compiler-options/27808 "2018-07-19T14:21:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mshulman256](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@mshulman256](https://discuss.gradle.org/u/mshulman256)\
**Post date:** [July 19, 2018, 2:21pm UTC](https://discuss.gradle.org/t/gradle-c-plugin-on-linux-how-to-insert-compiler-options/27808/1 "2018-07-19T14:21:37Z")

</div>

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 gradle.build 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:

```
-x
c
-c
-I
/home/me/mylib/inc
-isystem
/usr/local/include
-isystem
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include
-isystem
/usr/include
-m64

```

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 gradle.build. 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 gradle.build to put in these  
options.

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![mshulman256](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@mshulman256](https://discuss.gradle.org/u/mshulman256)\
**Post date:** [July 19, 2018, 4:02pm UTC](https://discuss.gradle.org/t/gradle-c-plugin-on-linux-how-to-insert-compiler-options/27808/2 "2018-07-19T16:02:27Z")

</div>

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'
	}
```
