c++macosqtstatic-librariesqbs

Qbs StaticLibrary on MacOS


I try to move an existing project from qmake to qbs, everything works fine so far but i can't link to google test static library in that project on MacOS while on windows it works fine.

On MacOS i get :-1: error: symbol(s) not found for architecture x86_64

GitHub repo of the project

googletest.qbs:

import qbs

StaticLibrary {
    name: "GoogleTest"
    files: [
        "googletest/googletest/src/gtest-all.cc",
        "googletest/googlemock/src/gmock-all.cc"
    ]

    cpp.includePaths: [
        "googletest/googletest/include",
        "googletest/googlemock/include",
        "googletest/googletest",
        "googletest/googlemock"
    ]

    Depends { name: "cpp" }
    Export {
        Depends { name: "cpp" }
        cpp.includePaths: [
            "googletest/googletest/include",
            "googletest/googlemock/include"
        ]
    }
}

test.qbs:

import qbs

QtApplication {
    name: "Test"
    targetName: "Test"

    Depends { name: "Qt"; submodules: ["core","testlib"]; versionAtLeast: "5.6" }
    Depends { name: "GoogleTest"}

    cpp.cxxLanguageVersion: "c++11"
    consoleApplication: true

    files: [
        "QtTypePrinters.h",
        "main.cpp",
        "QStringTest.cpp"
    ]
}

Solution

  • You need to set the following properties in your static library product:

    cpp.cxxLanguageVersion: "c++11"
    cpp.cxxStandardLibrary: "libc++"
    cpp.minimumMacosVersion: "10.7" // or higher
    

    By default, Qbs simply lets the compiler infer the defaults. gtest happens to require C++11 and libc++, which in turn is only supported by Apple on macOS 10.7 and above.