在 Qt 中链接具有非标准名称的 lib 文件

Linking a lib file with a non-standard name in Qt

在 Windows,我正在尝试将外部 DLL 添加到我的 Qt 项目(通过 Qt Creator)。我尝试引用以下生成的工件:

添加 library/dll 在我的 .pro 文件中生成以下条目:

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/target/release/ -lmylib.dll
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/target/debug/ -lmylib.dll

INCLUDEPATH += $$PWD/target/debug
DEPENDPATH += $$PWD/target/debug

Qt 期望 "mylib.dll.lib" 被命名为 "mylib.lib",因此使用上述配置构建失败并显示错误:

error: LNK1104: cannot open file 'mylib.lib'

如果我将 "mylib.dll.lib" 重命名为 "mylib.lib",构建工作正常,但如果可能的话,我不想引入这个额外的步骤。 dll.lib 后缀由 Rust/Cargo 和 there aren't any plans to allow this to be configured.

生成

经过一些研究,我尝试了几个不同的选项,包括在 PRE_TARGETDEPS 中引用它,但我无法使 LNK1104 错误消失。我错过了什么?

我明白了。诀窍是直接引用文件(即不使用 -L / -l 参数),如下所示:

win32:CONFIG(release, debug|release): LIBS += $$PWD/target/release/mylib.dll.lib
else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/target/debug/mylib.dll.lib

win32:CONFIG(release, debug|release): LIBS += $$PWD/target/release/mylib.dll
else:win32:CONFIG(debug, debug|release): LIBS += $$PWD/target/debug/mylib.dll