# Gradle.build c project component issues

**URL:** <https://discuss.gradle.org/t/gradle-build-c-project-component-issues/12049>\
**Category:** Help/Discuss\
**Created:** [October 6, 2015, 12:59pm UTC](https://discuss.gradle.org/t/gradle-build-c-project-component-issues/12049 "2015-10-06T12:59:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![blubee](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/blubee/32/2980_2.png) [@blubee](https://discuss.gradle.org/u/blubee)\
**Post date:** [October 6, 2015, 12:59pm UTC](https://discuss.gradle.org/t/gradle-build-c-project-component-issues/12049/1 "2015-10-06T12:59:07Z")

</div>

I am trying to get gradle to build a c project not c++

This is a sub module from an eventually larger project the structure is like this  
[![](http://i.imgur.com/oQb52Vg.png) ](http://i.imgur.com/oQb52Vg.png)

now when i run gradle components I get this output  
source sets  
C source 'core\_engine:c’  
srcDir: ‘src/core\_engine/c’

this seems to not pick up the header/ src project structure. I was watching this talk: [https://www.youtube.com/watch?v=ihOWmYjujnY](https://www.youtube.com/watch?v=ihOWmYjujnY)

for how to structure the project. That talk says that gradle uses sane defaults with exported src and header files being in src & headers directories but this output doesn’t seem like its being setup properly.

I almost forgot, here is the build.gradle file that’s is outputting this

apply plugin: ‘c’

model {  
components {  
core\_engine(NativeLibrarySpec) {  
}  
}  
}

am i doing something wrong? I don’t seem to be setting something wrong.

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [October 6, 2015, 1:27pm UTC](https://discuss.gradle.org/t/gradle-build-c-project-component-issues/12049/2 "2015-10-06T13:27:48Z")

</div>

The defaults are “src/${[component.name](http://component.name)}/${language}” and “src/${[component.name](http://component.name)}/headers”, so in your case it would be “src/core\_engine/c” and “src/core\_engine/headers”.

Here’s a sample for changing the source directories to something else (src/source): [https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/custom-layout/build.gradle](https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/custom-layout/build.gradle)

---

<div class="post-metadata">

**Author:** ![blubee](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/blubee/32/2980_2.png) [@blubee](https://discuss.gradle.org/u/blubee)\
**Post date:** [October 7, 2015, 3:07am UTC](https://discuss.gradle.org/t/gradle-build-c-project-component-issues/12049/3 "2015-10-07T03:07:47Z")

</div>

> [@sterling](#):
>
> [https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/custom-layout/build.gradle](https://github.com/gradle/gradle/blob/master/subprojects/docs/src/samples/native-binaries/custom-layout/build.gradle)

thank you for the link and the explanation.

---

<div class="post-metadata">

**Author:** ![blubee](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/blubee/32/2980_2.png) [@blubee](https://discuss.gradle.org/u/blubee)\
**Post date:** [October 9, 2015, 7:59am UTC](https://discuss.gradle.org/t/gradle-build-c-project-component-issues/12049/4 "2015-10-09T07:59:52Z")

</div>

I apologize for bringing this issue back up but I restructured my code a little bit to fit in with the default gradle folder structure and tried to build a shared library but the build directory comes out empty.

Here are some screenshots of my process

This is the first screenshot showing the directory layout and the source files  
 ![](https://global.discourse-cdn.com/gradle/original/2X/c/cc668d63813fbffc3718e98073196e689e4f9817.png)

this is the components view from gradle

 ![](https://global.discourse-cdn.com/gradle/original/2X/4/4fe8c20ad7635007e4e5e6f667100ee9d295af65.png)

this is the tasks view from gradle

 ![](https://global.discourse-cdn.com/gradle/original/2X/0/04034b84c0fe64af0f2ad82455bf75c5b02048e6.png)

This is me running the build command which turns out successful

 ![](https://global.discourse-cdn.com/gradle/original/2X/0/095f7ea1293e671dc78af842ffc796ebdbd2e455.png)  
This is the tree view after running the build shared library command, the folder is empty  
 ![](https://global.discourse-cdn.com/gradle/original/2X/8/8682821143ac8662793584ec704c58a2114e7b06.png)

I don’t have an executable atm since I am working on these components and will add an executable later.

Just a quick edit:  
I am able to use gcc to compile the shared library like this:  
bash-3.2$ gcc -shared -I/Users/blubee/SDL/bluengine/source/core\_engine/headers/core\_engin  
e.h -lSDL2 -o ce src/c/core\_engine.c

so by manually adding the linker args to gcc I can build. I tried editing my build.gradle to add -lSDL2 to the binaries.all but that’s still giving me a empty build directory with a successful build.

Here’s is the text of my build.gradle

apply plugin: ‘c’

model {  
components {  
core\_engine(NativeLibrarySpec) {  
binaries.all {  
cCompiler.args “-lSDL2”  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [October 9, 2015, 1:17pm UTC](https://discuss.gradle.org/t/gradle-build-c-project-component-issues/12049/5 "2015-10-09T13:17:33Z")

</div>

Take a look at the component report again (srcDir for core\_engine is src/core\_engine/c) and the layout you have now (src/c/).

---

<div class="post-metadata">

**Author:** ![blubee](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/blubee/32/2980_2.png) [@blubee](https://discuss.gradle.org/u/blubee)\
**Post date:** [October 9, 2015, 3:42pm UTC](https://discuss.gradle.org/t/gradle-build-c-project-component-issues/12049/6 "2015-10-09T15:42:22Z")

</div>

> [@sterling](#):
>
> at the component report again (srcDir for core\_engine is src/core\_engine/c) and the layout you have now (src/c/).

oh wow, you are correct… That file structure thing seems a bit excessive

I had to change the directory structure to: src/core\_engine/c/core\_engine.c

Although since this is a fairly young project with not too much outside dependencies I’d just stick with gradle’s default.

Thanks for the tip again @sterling
