# Compile gdbus-codegen generated code (.c) in a cpp-application

**URL:** <https://discuss.gradle.org/t/compile-gdbus-codegen-generated-code-c-in-a-cpp-application/27507>\
**Category:** Help/Discuss\
**Created:** [June 26, 2018, 1:39pm UTC](https://discuss.gradle.org/t/compile-gdbus-codegen-generated-code-c-in-a-cpp-application/27507 "2018-06-26T13:39:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ephraim](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ephraim/32/7047_2.png) [@ephraim](https://discuss.gradle.org/u/ephraim)\
**Post date:** [June 26, 2018, 1:39pm UTC](https://discuss.gradle.org/t/compile-gdbus-codegen-generated-code-c-in-a-cpp-application/27507/1 "2018-06-26T13:39:15Z")

</div>

I’ve a cpp-application which wants to use dbus. The interface is provided by an xml and translated via gdbus-codegen to c-code but my project is a cpp-code project.

Building the cpp-application with a custom task which calls gdbus-codegen is working so far except, that source.from doesn’t accept .c files and so ignores them totaly.

Is there a way to include c-files in a cpp-applcation. Just renaming doesn’t work as they will bring compile errors when seen as cpp files. So the c-files need to be compiled as c-code too.

---

<div class="post-metadata">

**Author:** ![ephraim](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ephraim/32/7047_2.png) [@ephraim](https://discuss.gradle.org/u/ephraim)\
**Post date:** [June 27, 2018, 12:42pm UTC](https://discuss.gradle.org/t/compile-gdbus-codegen-generated-code-c-in-a-cpp-application/27507/2 "2018-06-27T12:42:01Z")

</div>

Made it work via a cpp-library subproject which is static linked.  
and the compilerArgs for this cpp-library set to ["-x", “c”, “-std=gnu11”]

So the subproject is compiled via ccp compiler but with -x c to compile as C code.

And the main project is compiled via cpp compiler with -x c++ and statically linked against that subproject.
