Gradle not linking library?


I’m compiling the google-test example, and I get the following error:

[org.gradle.internal.operations.logging.DefaultBuildOperationLoggerFactory] C:\Program Files\Jenkins\workspace\google-test\build\objs\operatorsTestGoogleTestExe\failing\operatorsTestCpp\cwowpojzjknsgr3i9evu64iig\test_plus.obj:test_plus.cpp:(.text+0x4f): undefined reference to `testing::Message::Message()'

It doesn’t complain about the include though, so that seems to work fine. If I change the filename it doesn’t work.

All I have in my test_main.cpp is:

#include "gtest/gtest.h"

using namespace testing;

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();

and my build.gradle:

apply plugin: "cpp"
apply plugin: "google-test"

model {
    flavors {
    platforms {
        x86 {
            architecture "x86"
    repositories {
        libs(PrebuiltLibraries) {
            googleTest {
                headers.srcDir "libs/googleTest/1.7.0/include"
                binaries.withType(StaticLibraryBinary) {
                    staticLibraryFile =
                        file("libs/googleTest/1.7.0/lib/" +
    components {
        operators(NativeLibrarySpec) {
            targetPlatform "x86"

binaries.withType(GoogleTestTestSuiteBinarySpec) {
    lib library: "googleTest", linkage: "static"

    if (flavor == flavors.failing) {
        cppCompiler.define "PLUS_BROKEN"

tasks.withType(RunTestExecutable) {
    args "--gtest_output=xml:test_detail.xml"

def findGoogleTestCoreLibForPlatform(Platform platform) {'Platform check')
    if ( {
        return "vs2013/gtest.lib"
    } else if (platform.operatingSystem.macOsX) {
        return "osx/libgtest.a"
    } else {
        return "linux/libgtest.a"

What could cause this?

I’m having the similar problems. Although I am using running the testing tasks from jenkins in a Ubuntu server. If I run it in a windows machine I have no problem.

Any suggestion about what it might be?


How did you resolve this problem? I too is facing a similar problem.


Referred the [link] ( and section "Include pre-built libraries in native binary projects"
Could resolve the problem. Thanks

I’m a little bit late to the game. Could you give more information regarding the compiler used as well as the operating system used? I just double checked and the original code of this thread works without major problem. You still have to migrate the binaries container to be in the model but everything compiles, links, and runs fine.