# Generating C++ code using gradle for cpp\\source-generation

**URL:** <https://discuss.gradle.org/t/generating-c-code-using-gradle-for-cpp-source-generation/42188>\
**Category:** Help/Discuss\
**Created:** [February 11, 2022, 10:36am UTC](https://discuss.gradle.org/t/generating-c-code-using-gradle-for-cpp-source-generation/42188 "2022-02-11T10:36:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yehudnoa](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yehudnoa](https://discuss.gradle.org/u/yehudnoa)\
**Post date:** [February 11, 2022, 10:36am UTC](https://discuss.gradle.org/t/generating-c-code-using-gradle-for-cpp-source-generation/42188/1 "2022-02-11T10:36:39Z")

</div>

In gradles github repo for c, c++, swift samples of modern build automation for native languages with Gradle ([Gardle/Native-Samples](https://github.com/gradle/native-samples)) there is a project in the cpp folder called source-generation. This project is supposed to generate a cpp and header file in a folder labeled build. According to the readme the correct way to generate and compile this build is:

```gradle
> cd cpp/source-generation
> ./gradlew assemble

BUILD SUCCESSFUL in 1s

> ./build/install/main/debug/app
Hello, World!

```

but that doesn’t seem so work, neither does using the lazy API `build.gradle`.  
Any one get this to work or have any incite?

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [February 12, 2022, 12:08am UTC](https://discuss.gradle.org/t/generating-c-code-using-gradle-for-cpp-source-generation/42188/2 "2022-02-12T00:08:00Z")

</div>

I guess you found a Gradle bug that you should report.  
In the example the directory properties miss their task dependency.  
If you instead make the two properties abstract getter methods, the task dependency is maintained as expected and the build works like intended.

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [February 17, 2022, 3:48pm UTC](https://discuss.gradle.org/t/generating-c-code-using-gradle-for-cpp-source-generation/42188/3 "2022-02-17T15:48:38Z")

</div>

Maybe post the issue link here too for others as reference. 🙂

---

<div class="post-metadata">

**Author:** ![yehudnoa](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yehudnoa](https://discuss.gradle.org/u/yehudnoa)\
**Post date:** [February 18, 2022, 12:04pm UTC](https://discuss.gradle.org/t/generating-c-code-using-gradle-for-cpp-source-generation/42188/4 "2022-02-18T12:04:41Z")

</div>

> [@Vampire](#):
>
> In the example the directory properties miss their task dependency.

There are currently almost 100 different issues with C++ in the gradles issues but never the less I added this one so I hope its not a duplicate 😊  
[Link to issue](https://github.com/gradle/gradle-native/issues/1095)
