简体   繁体   English

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

[英]Linking a lib file with a non-standard name in Qt

On Windows, I'm attempting to add an external DLL to my Qt project (via Qt Creator). 在Windows上,我尝试将外部DLL添加到我的Qt项目中(通过Qt Creator)。 I have the following generated artifacts I'm trying to reference: 我尝试引用以下生成的工件:

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

Adding the library/dll generates the following entry in my .pro file: 添加库/ 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 is expecting "mylib.dll.lib" to be named "mylib.lib", so with the above configuration the build fails with the error: Qt期望将“ mylib.dll.lib”命名为“ mylib.lib”,因此使用上述配置,构建将失败,并显示以下错误:

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

The build works correctly if I rename "mylib.dll.lib" to "mylib.lib", but I'd rather not introduce this extra step, if possible. 如果我将“ mylib.dll.lib”重命名为“ mylib.lib”,则构建可以正常工作,但如果可能的话,我宁愿不介绍此额外步骤。 The dll.lib suffix is generated by Rust/Cargo, and there aren't any plans to allow this to be configured . dll.lib后缀是由Rust / Cargo生成的, 尚无任何计划对其进行配置

After doing some research, I've tried a couple of different options, including referencing it in PRE_TARGETDEPS , but I can't make the LNK1104 error disappear. 在进行了一些研究之后,我尝试了几种不同的选择,包括在PRE_TARGETDEPS对其进行PRE_TARGETDEPS ,但是我无法使LNK1104错误消失。 What am I missing? 我想念什么?

I figured it out. 我想到了。 The trick is to refer to the files directly (ie not using the -L / -l parameters), like this: 技巧是直接引用文件(即不使用-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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM