MacOS 上的 Qbs 静态库

Qbs StaticLibrary on MacOS

我尝试将现有项目从 qmake 移动到 qbs,到目前为止一切正常,但我无法 link 到 google 在 MacOS 上测试该项目中的静态库,同时 windows 它工作正常。

在 MacOS 上我得到 :-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"
    ]
}

您确定这是来自链接器的完整错误消息吗?当然也提到了实际缺失的符号?

您需要在静态库产品中设置以下属性:

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

默认情况下,Qbs 只是让编译器推断默认值。 gtest 恰好需要 C++11 和 libc++,而后者仅在 macOS 10.7 及更高版本上受 Apple 支持。