1

我有一个由 cmake 构建的子模块,并在 qbs 脚本中成功构建它(见下面的代码)。

Product {
name: "mylib"
type: ["staticlibrary"]

// define buildScript, outputPath, libPrefix, libExt, cmakeBuildType, cmakeBuildConfig
// Note that outputPath is inside mylib folder, not qbs's build directory

Rule {
    multiplex: true
    outputArtifacts: [
        {
            filePath: product.outputPath + product.libPrefix + "lib1static" + product.libExt,
            fileTags: ["staticlibrary"]
        },
        {
            filePath: product.outputPath + product.libPrefix + "lib2static" + product.libExt,
            fileTags: ["staticlibrary"]
        }
    ]
    outputFileTags: ["staticlibrary"]
    prepare: {
        var cmd = new Command(product.buildScript, [product.outputPath, product.cmakeBuildType, product.cmakeBuildConfig]);
        cmd.description = "cmake generate mylib";
        cmd.workingDirectory = product.sourceDirectory + "/mylib/build_cmake";

        return [cmd];
    }
}

但是,有时 qbs 会删除“lib1static”和“lib2static”,并且在链接时出现此错误:

clang: error: no such file or directory: '<path>/lib1static.a'
clang: error: no such file or directory: '<path>/lib2static.a'

我试图调试,但仍然不知道为什么。第一次构建可以成功,所有输出库都已构建,但在下一次构建中,所有库都消失了。

这里的任何人都可以解释并告诉我这种情况下哪个是最佳实践吗?

4

1 回答 1

0

我不明白为什么文件会被删除。但是,还有另一个问题:如上所示的规则只会运行一次,因为它没有输入,因此您的子项目的源文件中的更改将不会被拾取。(并且,作为旁注:如果输出不是“动态的”,您可以声明 Artifact 项目,而不是使用 outputArtifacts 和 outputFileTags 属性。)试试这个:

Rule {
    multiplex: true
    alwaysRun: true
    Artifact {
        filePath: product.outputPath + product.libPrefix + "lib1static" + product.libExt
        fileTags: ["staticlibrary"]
        alwaysUpdated: false
    }
    Artifact {
        filePath: product.outputPath + product.libPrefix + "lib2static" + product.libExt
        fileTags: ["staticlibrary"]
        alwaysUpdated: false
    }
    prepare: {
        var cmd = new Command(product.buildScript, [product.outputPath, product.cmakeBuildType, product.cmakeBuildConfig]);
        cmd.description = "cmake generate mylib";
        cmd.workingDirectory = product.sourceDirectory + "/mylib/build_cmake";

        return [cmd];
    }
}
于 2018-06-04T09:31:52.617 回答