c++ - Qt qbs 项目设置与库未找到编译错误

标签 c++ linux qt ubuntu qbs

我正在开发一个有多个级别的项目。就我个人而言,我对qbs还是个新手,内部关于qbs的文档和示例并不多。

环境:

Qt5.6.1; Qt 创建者 4.01;乌类图16.04; Qbs 1.5.1

这是项目的层次结构。在顶层,它有project.qbs:

import qbs
import qbs.File
Project{
    var binaries = [
        "component1/component1.qbs",
        "component2/component2.qbs",
        "subpro/subpro.qbs",         // <- 1. the project I am working on
        "ourlib/ourlib.qbs",         // <- 2. the library I am using
    ]
    return binaries
}

subpro.qbs 类似于:

import qbs
Project {
    name: subpro
    references:[
        "app1/app1.qbs"
        "app2/app2.qbs"
        "myapp/myapp.qbs"          //<- 3. the application I am working on
    ]

}

myapp.qbs 就像:

import qbs
CppApplication{
    type: "application"
    name: "myapp"
    Group{
        name: "project-install"
        fileTagsFilter: "application"
        qbs.install: false
        qbs.install: "bin"
    }
    Depends {name:"cpp"}
    Depends {name:"blah1"}
    Depends {name:"ourlib"}

    cpp.libraryPaths:["path_of_lib3rdParty"] // 4. set the 3rd party lib path
    cpp.staticLibraries:["lib3rdParty.a"]    // 5. set the 3rd party lib name

    files["myapp.cpp","f2"...]
}

最后是我们库的 qbs:

import qbs
DynamicLibrary{
    name: "ourlib"
    Group{
        name: "project-install"
        fileTagsFilter: "dynamiclibrary"
        qbs.install: false
        qbs.installDir: "debug"
    }

    Depends {name: "cpp"}
    cpp.includePath:["..."]
    cpp.libraryPaths:["path_of_lib3rdParty"] // 6. same as 4
    cpp.staticLibraries:["lib3rdParty.a"]    // 7. same as 5
}

当我在项目根文件夹下运行“qbs debug”时。 qbs 显示:

linking ourlib.so
compiling myapp.cpp
ERROR: ...
/usr/bin/ld: cannot find -llib3rdParty_s.a

因此,根据错误消息,qbs 无法构建 myapp.cpp 并尝试在 myapp 项目中找到 lib3rdParty。我添加了4和5,仍然有同样的错误。看来 6 和 7 是正确的,因为 ourlib.so 没有链接错误。我应该如何配置 qbs 以使构建过程正常运行?

另一个问题是关于关键字“references”的。我可以在项目中的任何级别引用其他 qbs 文件吗?它是如何工作的?我也对“取决于”有同样的问题。

谢谢

最佳答案

cpp.dynamicLibrariescpp.staticLibraries 属性采用要链接的库名称列表,即不带 lib 前缀或 .so 后缀。

例如,您可以使用:

cpp.libraryPaths: ["/home/r0ng/tools/myapp/libs/relic/lib"]
cpp.dynamicLibraries: ["relic"]

但是,由于您已经拥有要链接的动态库的完整文件路径,因此您可以简单地传递完整文件路径,而无需指定 cpp.libraryPaths,如下所示:

cpp.dynamicLibraries: ["/home/r0ng/tools/myapp/libs/relic/lib/librelic.so"]

第二种方法是首选,因为它指定了要链接的确切库,而不是依赖于搜索路径,搜索路径可能不一定会选择您期望的库类型(如果静态和动态版本都存在)。

我承认我们的 cpp.dynamicLibrariescpp.staticLibraries 属性应该更好地记录下来以解释其预期用途。


关于引用,是的,您可以引用任何文件路径,无论其文件系统位置如何。


关于Depends,该项目的name属性指定要创建依赖项的产品或模块的名称。此类产品或模块必须已存在于您的项目树中,例如已因使用 qbsSearchPathsreferences 属性而加载。

关于c++ - Qt qbs 项目设置与库未找到编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38318224/

相关文章:

c++ - 当使用大于 3000 万的数据输入大小时,程序不会将数据输出到控制台

c++ - 为什么 ReadFile() 不返回 0 ?程序试图永远从管道中读取数据

linux - 计算用户登录 Linux 的时间的简单方法

c++ - 更新 : Memory Location being outputted instead of desired string

linux - 使用 Bash 获取特定文件的 mtime?

php - 在 Apache2/Linux (LAMP) 上为 PHP 网站设置文件权限的最佳做法是什么?

c++ - 我想在qt中创建一个自定义标题栏

c++ - 在 OSX 10.8.3 上安装 Qwt 6.02 时出错

visual-studio - 在 Visual Studio 中添加和删除文件 - 编译错误

c++ - 编译器如何编译if语句