Copying precompiled libraries to build directory or adding them to PATH in a QBS project

时光毁灭记忆、已成空白 提交于 2019-12-10 18:56:49

问题


I have a third party precompiled library (.lib+.dll) that I use in my Qt application.

In a regular (qmake) QtCreator project I have the following lines in my .pro file:

LIBS += -L$$PWD/lib/release -ltag
INCLUDEPATH += include/taglib

There is also an option in Projects tab -> Run -> "Add build library search path to PATH" which is by default ON. It ensures that LIBS path gets added to system PATH, so the dll can be found.

However, I can't find an equivalent in QBS. I have the following qbs file, which then gets included and added via Depends in my CppApplication file:

DynamicLibrary {
    name: "taglib"

    files: "lib/release/tag.dll"

    Export {
        Depends { name: "cpp" }
        cpp.includePaths: [".","include/taglib"]
        cpp.libraryPaths: ["lib/release"]
        cpp.dynamicLibraries: "tag"
    }

    Group {
        name: "taglib"
        fileTagsFilter: ["dynamicLibrary"]
        qbs.install: true
    }

}

The linker passes but the application can't find the DLL at runtime and crashes. Is it possible to add cpp.libraryPaths to system PATH at runtime?

Another option would be to copy the DLL file to build directory, but I can't figure out how to do that for precompiled libraries in QBS.

EDIT: I tried to use cpp.systemRunPaths which is documented here but it doesn't work.


回答1:


I figured out how to copy prebuilt .dll files to build dir.

What was missing was FileTagger property since it seems QBS doesn't consider .dll files dynamic libraries.

FileTagger {
    patterns: ["*.dll"]
    fileTags: ["dynamicLibrary"]
}

The question still stands on how to add cpp.libraryPaths to system PATH on runtime. I found the following method in core.qbs:

setupRunEnvironment: {
    var env;
    if (qbs.targetOS.contains('windows')) {
        env = new ModUtils.EnvironmentVariable("PATH", qbs.pathListSeparator, true);
        env.append(binPath);
        env.set();
    }
    ...
}

I have no idea how to modify or invoke that method in my QBS files.




回答2:


alan, your're on the right way. Just place

setupRunEnvironment: {
    var env;
    if (qbs.targetOS.contains('windows')) {
      env = new ModUtils.EnvironmentVariable("PATH", qbs.pathListSeparator, true);
      env.append(binPath);
      env.set();
    } 
}

in the DynamicLibrary {} block, below the last Group {}. Change binPath to point to the folder with your shared libraries. This works at least with Windows.

Maybe you need to move Depends { name: "cpp" } out of the Export block.



来源:https://stackoverflow.com/questions/39466967/copying-precompiled-libraries-to-build-directory-or-adding-them-to-path-in-a-qbs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!