How does one staticly link an already compiled library in a gradle C++ project?(by using the DSL - im currently using the linker.args)

here’s what im currently using:

sources {
 main {
  cpp {
   source {
    srcDir "src"
    include "*.cpp"
          binaries.all {
     if (toolChain in Gcc) {
      tasks.withType(CppCompile) {
       includes.from("${libSDLDistDir}/include")
      }
        linker.args path(["-L${libSDLDistDir}", "bin", "build", ".libs"])
      linker.args "-static"
      linker.args "-lSDL2"
      linker.args "-dynamic"
      linker.args "-lm"
      linker.args "-ldl"
      linker.args "-lpthread"
      linker.args "-lrt"
     }
    }
   }
  }
 }
}

You can configure prebuilt libraries. The userguide has an example in section 54.12.3 Running CUnit Tests. Note the model.repositories section that sets up the “cunit” prebuilt library, and then the linkage to it in the subsequent “binaries.withType()” block.

This is an area where you should expect gradle to be improved quite a bit in the future. There’s too much configuration required currently, and we should simplify this as much as possible.

exactly what i was looking for! thank you :slight_smile: