How can I link static lib to a static lib?

Hi all,

I am trying to link a static library to another static but I can’t make it work.

I have seen multiple examples available on this forum and on github but it doesn’t help.

Here is my build.gradle:

apply plugin: 'cpp'

model {
    buildTypes {

    repositories {
        lib(PrebuiltLibraries) {
            Secur32 {
                headers.srcDir "C:/Program Files/Microsoft SDKs/Windows/v7.0/Include"
                binaries.withType(StaticLibraryBinary) {
                    staticLibraryFile = file("C:/Program Files/Microsoft SDKs/Windows/v7.0/Lib/Secur32.lib")

    components {
        MyStaticLib(NativeLibrarySpec) {
            sources {
                cpp {
                    source {
                        srcDirs "implementation"
                        include "**/*.cpp"
                    exportedHeaders {
                        srcDirs "interface",
                        include "**/*.h", "**/*.hpp"
                    lib library: 'Secur32', linkage: 'static'


binaries.withType(SharedLibraryBinary) { binary ->
    buildable = false

When I look at the tmp file created with the options passed to the linker, I can’t see the options that I need which are:

/OUT:"${path_to_my_lib}\MyStaticLib.lib" Secur32.lib

I tried to directly add these options to linker.args but it doesn’t work either.

Am I missing something ?


Static libraries don’t link with other static libraries. Static libraries are basically an archive of object files. The linker isn’t involved, instead we use the staticLibArchiver tool.

What are you trying to do? Make a “fat” static library (project + dependencies)?

Hi Sterling,

My bad I didn’t express my issue correctly but you got it right. The solution that I needed was the staticLibArchiver

Here is the part that I added in case someone needs it:

binaries.withType(StaticLibraryBinary) {
  staticLibArchiver.args "C:/Program Files/Microsoft SDKs/Windows/v7.0/Lib/Secur32.lib"

Thanks a lot.