# CPP - Can I compile without linking?

**URL:** <https://discuss.gradle.org/t/cpp-can-i-compile-without-linking/3833>\
**Category:** Old Forum Archive\
**Created:** [January 14, 2014, 10:44am UTC](https://discuss.gradle.org/t/cpp-can-i-compile-without-linking/3833 "2014-01-14T10:44:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared\_Buletza](https://avatars.discourse-cdn.com/v4/letter/j/e0b2c6/32.png) [@Jared\_Buletza](https://discuss.gradle.org/u/Jared_Buletza)\
**Post date:** [January 14, 2014, 10:44am UTC](https://discuss.gradle.org/t/cpp-can-i-compile-without-linking/3833/1 "2014-01-14T10:44:00Z")

</div>

I would like to have gradle compile my native sources (linux cpp) to create the .o files, but not build an executable or a library. Is there an easy way to achieve this? Or do I need to specify “executable”, but just not have a main() function?

---

<div class="post-metadata">

**Author:** ![daz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daz/32/2475_2.png) [@daz](https://discuss.gradle.org/u/daz)\
**Post date:** [January 14, 2014, 6:30pm UTC](https://discuss.gradle.org/t/cpp-can-i-compile-without-linking/3833/2 "2014-01-14T18:30:00Z")

</div>

There are a couple of ways you can do this. Although it’s possible to apply just the ‘org.gradle.nativebinaries.plugins.NativeBinariesModelPlugin’ and&nbsp;create and configure a [CppCompile](http://www.gradle.org/docs/nightly/dsl/org.gradle.nativebinaries.language.cpp.tasks.CppCompile.html "Link: http://www.gradle.org/docs/nightly/dsl/org.gradle.nativebinaries.language.cpp.tasks.CppCompile.html") task to do just the compilation, it’s not trivial to get an instance of [ToolChain](http://www.gradle.org/docs/nightly/dsl/org.gradle.nativebinaries.toolchain.ToolChain.html "Link: http://www.gradle.org/docs/nightly/dsl/org.gradle.nativebinaries.toolchain.ToolChain.html")&nbsp;and [Platform](http://www.gradle.org/docs/nightly/dsl/org.gradle.nativebinaries.platform.Platform.html "Link: http://www.gradle.org/docs/nightly/dsl/org.gradle.nativebinaries.platform.Platform.html")&nbsp;to use.  
  
I would instead recommend defining an executable or library, and simply calling the appropriate compile task(s).
