如何动态包含 .lib 文件?
我的项目有问题。我正在 Qt Creator 上开发它,我需要将 .lib 文件添加到我的项目中。所以,我在我的 .pro 中写了这一行:
LIBS += "C:\My_Path\My_Project\lib\file.lib"
这工作正常。我唯一的问题是我需要写入 .lib 文件的整个路径。由于它是一个小组项目,因此需要在其他计算机上可以编译,而不需要每次都更改该文件的路径。
我尝试了很多语法,例如:
LIBS += -L"lib/" -l"file.lib"
或
LIBS += "lib\file.lib"
或
LIBS += "file.lib"
(将.lib文件放在根目录并将其添加到Qt Creator中的项目中)
它们都不起作用:/
我还尝试将.lib文件添加到QResource文件中,但是语法像这样:
LIBS += ":/lib/file.lib"
在 .pro 文件中似乎不起作用...
我现在没有想法了:(
请帮忙:)
I've got a problem with my project. I am developing it on Qt Creator, and I need to add a .lib file to my project. So, I wrote this line in my .pro :
LIBS += "C:\My_Path\My_Project\lib\file.lib"
This is working fine. My only issue is that I need to write the entire path to the .lib file. Since it's a group project, it needs to be compilable on other computers without changing the path to this file every times.
I tried many syntaxes, like :
LIBS += -L"lib/" -l"file.lib"
or
LIBS += "lib\file.lib"
or
LIBS += "file.lib"
(putting the .lib file at the root and adding it to the project in Qt Creator)
None of them works :/
I also tried to add the .lib file in a QResource file but a syntax like this one :
LIBS += ":/lib/file.lib"
in a .pro file doesn't seem to work...
I am now running out of ideas :(
Help please :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过
LIBS += -Llib -lfile
或
LIBS += -L./lib -lfile
?请记住,如果您不使用完整路径,则不要将
.lib
添加到库名称中,也不要使用引号。如果路径有空格(或者您只是想安全),请使用$$quote(-L)
如所述此处 Unix 样式路径也适用于 Windows,通常需要提供完整路径。 qmake 会帮你填写。
我将
LIBS += ../../lib/phraseBox.lib
转换为
LIBS += $$quote(-L../../lib) -lphraseBox
和
LIBS += $$quote(-L../../lib)phraseBox.lib
在我的一个项目中,在 Windows 上没有问题。您可能想将项目文件发布到某个地方,或者发布实际的错误消息来缩小范围。
Did you try
LIBS += -Llib -lfile
or
LIBS += -L./lib -lfile
?Remember if you aren't using the full path, you don't add
.lib
to the library name and you don't use quotes. If the path has spaces (or you just want to be safe), use$$quote(-L<path name>)
As stated here the Unix style paths work on Windows as well where you normally need to provide the full path. qmake will fill it in for you.
I converted
LIBS += ../../lib/phraseBox.lib
to
LIBS += $$quote(-L../../lib) -lphraseBox
and
LIBS += $$quote(-L../../lib) phraseBox.lib
In one of my project with no problem on Windows. You might want to post your project files somewhere, or post the actual error messages to narrow this down.
好的,我找到了解决方案:
lib/ 目录必须放在 Makefile 的同一目录中(真正的目录,而不是 .pro)。
由于我将 lib/ 目录复制到了 build-desktop/ 目录中,因此使用相对路径一切正常:)
Ok, I found the solution :
the lib/ directory has to be placed in the same directory that the Makefile (the real one, not the .pro).
Since I copied the lib/ directory in the build-desktop/ directory, everything is working fine using relative paths :)
根据您的尝试,我猜您想使用相对路径链接到库,默认情况下该路径应该可以正常工作。
试试这个:
如果它不起作用,那么您可能需要尝试设置多个
包含路径
。 :/From your tries I guess you want to link to the library using relative path which should work just fine by default.
Try this:
If it does not work, then you might want to try setting multiple
INCLUDEPATH
. :/