我尝试将现有项目从qmake移至qbs,到目前为止一切正常,但是我无法在MacOS上链接到该项目中的Google测试静态库,而在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支持。

关于c++ - MacOS上的Qbs StaticLibrary,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47496052/

10-11 15:46