Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ with gradle

Tags:

c++

gradle

In Gradle 1.10 Release notes http://www.gradle.org/docs/current/release-notes I see C++ build mentioned.

How to set up C++ project to build with gradle? (without IDE)

Suppose I have

ProjectFolder/hello.cpp ProjectFolder/build.gradle 

hello.cpp:

#include <stdio.h> #include <stdlib.h>  int main(void) {     puts("Hello World!!!");     return EXIT_SUCCESS; } 

What should basic build.gradle be for this C++ project?

UPDATE: I have already looked at Chapter 72 of User Guide and 2 year old examples mentioned. They don't make it simpler but more complicated.

There is 1 file example with 6 lines. I haven't been touching C++ for 10 year and I just wanted quick start e.g. with GCC . (Not yet found)

like image 977
Paul Verest Avatar asked Jan 11 '14 06:01

Paul Verest


People also ask

Does Gradle support C?

This support is available for C, C++, Objective-C, and Objective-C++ builds. To configure a precompiled header, first a header file needs to be defined that includes all of the headers that should be precompiled.

Can you use Gradle for C++?

Gradle has general support for the three major tool chains on major operating system: Clang, GCC and Visual C++ (Windows-only).

What does N mean in Gradle?

Issuing gradlew dependencies | tail shows a legend explaining the meaning of the printed suffixes. (c) - dependency constraint (*) - dependencies omitted (listed previously) (n) - Not resolved (configuration is not meant to be resolved)

Is Gradle a compiler?

Gradle-Android compiler Both plugins are bundled and enabled by default. Use this page to specify settings for compiling Android-Gradle projects. For the additional information on the build process, refer to the Android documentation.


2 Answers

  1. put this in build.gradle

    apply plugin: 'cpp' executables {    hello {} } 
  2. put your source file in src/hello/cpp/say_hello.cpp

  3. run 'gradle helloExecutable'

  4. your executable should be built to build/binaries/helloExecutable/hello

Or, if you want your source in src/foo/bar then add

sources {     hello {       cpp {         source {             srcDir "src/foo/bar"         }     } } 
like image 192
Perryn Fowler Avatar answered Sep 20 '22 15:09

Perryn Fowler


Starting on Gradle 2.3 there have been major changes to native-component builds and the executables and libraries containers are not available anymore. Citing Gradle 2.3 Release notes:

... the DSL for defining native executables and libraries has fundamentally changed. The executables and libraries containers have been removed, and components are now added by type to the components container owned by the model registry. Another major change is that source sets for a component are now declared directly within the component definition, instead of being configured on the sources block.

The updated Gradle code compatible with Gradle 2.3+ will therefore look like:

model {   components {     hello(NativeExecutableSpec) {       sources {         cpp {           source {             srcDir "src/foo/bar"           }         }       }     }   } } 

You can learn more about the new model in Gradle user guide here.

like image 20
Amnon Shochot Avatar answered Sep 22 '22 15:09

Amnon Shochot