Building a c program with gradle

I am new to creating a c / cpp plugin in gradle. This is the project structure.

.
|-- build.gradle
`-- src
    `-- main
        `-- c
            `-- hello.c

Content hello.c

#include <stdio.h>

int main(int argc, char** argv){
    printf("Hello World!\n");
    return 0;
}

Build.gradle content

apply plugin: 'c'

executables {
    main {
    }
}

When I run: $ gradle mE, I get the following error

FAILURE: Build failed with an exception.

* Where:
Build file '/home/sujith/Downloads/cpp-examples-master/gradle-c-plugin/03-executable/build.gradle' line: 3

* What went wrong:
A problem occurred evaluating root project '03-executable'.
> Could not find method executables() for arguments [build_aaxd7x5nukew1jgziyan9q177$_run_closure1@57552dfc] on root project '03-executable'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.297 secs

Sample project taken from https://github.com/ysoftdevs/cpp-examples

Gradle version:

$ gradle -version

------------------------------------------------------------
Gradle 2.3
------------------------------------------------------------

Build time:   2015-02-16 05:09:33 UTC
Build number: none
Revision:     586be72bf6e3df1ee7676d1f2a3afd9157341274

Groovy:       2.3.9
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.7.0_67 (Oracle Corporation 24.65-b04)
OS:           Linux 3.13.0-24-generic amd64

Am I missing something? Any help is appreciated. Thanks you

+4
source share
1 answer

I ran into the same problem when the use is executables { ... }not working and it produces the same error as you mentioned. It was probably used in an older version of gradle.

I referred to gradle docs for creating my own binaries.

build.gradle:

apply plugin: 'c'

model {
  components {
    main(NativeExecutableSpec) {}
  }
}

.

gradle tasks, , .

gradle build build/binaries/mainExecutable/main.

, , , , C.

, .

EDIT. , . , build.gradle. clincher , executables {...}, libraries {...} .., , , , .

+4

All Articles