Don Wagner
Don Wagner

Reputation: 11

Adding linker arguments to gradle

I am trying to use gradle to compile and link an application on Linux. The compile section works fine, but when it links, it get undefined items because the libraries are not included for the linker. I tried multiple ways to add it (see below), but none of them see to work. Do you know what I need to do to include the libraries for the liker?

plugins {
    // Apply the cpp-application plugin to add support for building C++ executables
    id 'cpp-application'
}

model {
    binaries {
        all {
            linker.args "-lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread"
        }
    }
}

// Set the target operating system and architecture for this application
application {
    privateHeaders {
       from('src/headers')
       from('/usr/include/qt5')
       from('/usr/include/qt5/QtCore')
       from('/usr/include/qt5/QtGui')
       from('/usr/include/qt5/QtWidgets')
       }
    source.from file('src/cpp')
    println source
    binaries.configureEach {
        compileTask.get().compilerArgs.add('-O2')
        compileTask.get().compilerArgs.add('-fPIC')
        compileTask.get().compilerArgs.add('-std=gnu++11')
        println compileTask.get()
        //linker.args '-lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread'
        //println createTask.get()
        //println LinkExecutable.getLinkerArgs()
        //linkerTask.get().linkerArgs.add('-lQt5Widget')
        //linkerTask.get().linkerArgs.add('-lQt5Gui')
        //linkerTask.get().linkerArgs.add('-lGl')
        //linkerTask.get().linkerArgs.add('-lpthread')
    }
}

Upvotes: 1

Views: 553

Answers (0)

Related Questions