- Crear una carpeta para un proyecto C++
- Generar un proyecto C++ con Gradle
- Editar archivo principal
- Construir y ejecutar
$ mkdir pruebasCpp && cd pruebasCpp
$ gradle init Select type of project to generate: 1: basic 2: application 3: library 4: Gradle plugin Enter selection (default: basic) [1..4] 2
Select implementation language: 1: C++ 2: Groovy 3: Java 4: Kotlin 5: Scala 6: Swift Enter selection (default: Java) [1..6] 1
Select build script DSL: 1: Groovy 2: Kotlin Enter selection (default: Groovy) [1..2] 1
Listemos el el contenido del directorio:
$ tree . ├── app │ ├── build │ │ ├── exe │ │ │ └── main │ │ │ └── debug │ │ │ └── app │ │ ├── install │ │ │ └── main │ │ │ └── debug │ │ │ ├── app │ │ │ └── lib │ │ │ └── app │ │ ├── obj │ │ │ ├── for-test │ │ │ │ └── main │ │ │ │ └── debug │ │ │ │ └── app.o │ │ │ └── main │ │ │ └── debug │ │ │ └── c0rn65lkroj8p4fvz0qgmzzjr │ │ │ └── app.o │ │ ├── test-results │ │ │ └── test │ │ └── tmp │ │ ├── compileDebugCpp │ │ │ ├── options.txt │ │ │ └── output.txt │ │ ├── compileTestCpp │ │ │ ├── options.txt │ │ │ └── output.txt │ │ ├── linkDebug │ │ │ ├── options.txt │ │ │ └── output.txt │ │ └── linkTest │ │ ├── options.txt │ │ └── output.txt │ ├── build.gradle.kts │ └── src │ └── main │ ├── cpp │ │ └── app.cpp │ └── headers │ └── app.h ├── gradle │ └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle.kts
Observemos nuestro archivo "build" generado.
build.gradle.kts
/* * This file was generated by the Gradle 'init' task. * * This generated file contains a sample C++ project to get you started. * For more details take a look at the Building C++ applications and libraries chapter in the Gradle * User Manual available at https://docs.gradle.org/7.2/userguide/building_cpp_projects.html */ plugins { // Apply the cpp-application plugin to add support for building C++ executables `cpp-application` // Apply the cpp-unit-test plugin to add support for building and running C++ test executables `cpp-unit-test` } // Set the target operating system and architecture for this application application { targetMachines.add(machines.linux.x86_64) }
app.cpp
/* * This C++ source file was generated by the Gradle 'init' task. */ #include <iostream> #include <stdlib.h> #include "app.h" std::string demo::Greeter::greeting() { return std::string("Hola mundo desde Codemonkey Junior!!"); } int main () { demo::Greeter greeter; std::cout << greeter.greeting() << std::endl; return 0; }
$ ./gradlew build $ ./app/build/exe/main/debug/app Hola mundo desde Codemonkey Junior!!
Enlaces:
https://gradle.org/