【问题标题】:Linking a lib file with a non-standard name in Qt在 Qt 中使用非标准名称链接 lib 文件
【发布时间】:2018-07-21 03:23:06
【问题描述】:

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

  • 目标/调试/mylib.d
  • 目标/调试/mylib.dll
  • 目标/调试/mylib.dll.d
  • 目标/调试/mylib.dll.lib

添加库/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 错误消失。我错过了什么?

【问题讨论】:

    标签: c++ qt qt-creator


    【解决方案1】:

    我想通了。诀窍是直接引用文件(即不使用-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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      相关资源
      最近更新 更多