关于QT加载lib与dll的一点评论
2013-08-16 17:12
375 查看
On Windows, you always link against a .lib file, even if the library itself is in a DLL. What you normally have to do to use an external library, on any platform, is:
1) Add the library to the LIBS variable in your .pro file:
LIBS += -llibrary
2) Add the library path to the LIBS variables
in your .pro file:
LIBS += -LC:/path/to/library
3) Add the include path to the INCLUDEPATH variable
in your .pro file:
INCLUDEPATH += C:/path/to/includes
Then, if the library is a DLL, you must make sure the DLL is found when you run the program. On Windows you can
e.g. add it the same directory as your executable. If you run the application from Qt Creator, it seems to be able to locate the DLL itself (if it’s in the same place as the .lib file, I would guess).
Just to clear it up.. You can choose to link statically or dynamically, statically meaning the library is bundled along with your app, dynamic uses a dll. Now, if you have a .lib and a .dll, you have a library made to be used
dynamically. You cannot use that .lib file statically, the static .lib is generally named (<somename>_a.lib), is of a bigger size than the .lib in the case of dynamic libraries. This is because the static .lib has to contain all the implementation, while in
the dynamic .lib, you only have the exported symbols, and the actual implementation is in the dll.
@matthazley: You have a .lib and .dll but do you also have the header files (.h).. that is the general way to link to a library. You include the header in your code and use the methods. Compile with linking to the .lib. At
runtime this loads the dll which has the implementation. Refer to @ludde for the definitions in the pro file.
1) Add the library to the LIBS variable in your .pro file:
LIBS += -llibrary
2) Add the library path to the LIBS variables
in your .pro file:
LIBS += -LC:/path/to/library
3) Add the include path to the INCLUDEPATH variable
in your .pro file:
INCLUDEPATH += C:/path/to/includes
Then, if the library is a DLL, you must make sure the DLL is found when you run the program. On Windows you can
e.g. add it the same directory as your executable. If you run the application from Qt Creator, it seems to be able to locate the DLL itself (if it’s in the same place as the .lib file, I would guess).
Just to clear it up.. You can choose to link statically or dynamically, statically meaning the library is bundled along with your app, dynamic uses a dll. Now, if you have a .lib and a .dll, you have a library made to be used
dynamically. You cannot use that .lib file statically, the static .lib is generally named (<somename>_a.lib), is of a bigger size than the .lib in the case of dynamic libraries. This is because the static .lib has to contain all the implementation, while in
the dynamic .lib, you only have the exported symbols, and the actual implementation is in the dll.
@matthazley: You have a .lib and .dll but do you also have the header files (.h).. that is the general way to link to a library. You include the header in your code and use the methods. Compile with linking to the .lib. At
runtime this loads the dll which has the implementation. Refer to @ludde for the definitions in the pro file.
相关文章推荐
- 关于dll和lib(傻乎乎的我 又学到一点)
- 关于Qt动态加载dll时,函数指针取地址OK,使用时却有问题
- Qt中加载Libevent静态库(通过reimp和rs两条语句将lib转为a)
- 关于Qt5.10调试时出现“qtcreatorcdbext.dll cannot be found.”的解决方案
- 关于无法加载 DLL (dFastlog.dll)的错误
- 静态链接库(LIB)和动态链接库(DLL),DLL的静态加载和动态加载,两种LIB文件。
- 一点关于Qt的简介
- 关于.h .lib .dll的总结
- VC6.0中加载库(lib、dll)文件的两种方法
- C/C++ 关于生成静态库(lib)/动态库(dll)文件如何使用(基于windows基础篇)
- 关于QT stylesheet的使用的一点见解
- 关于Windows平台下应用程序加载DLL模块的问题.
- ubuntu系统启动qtceator时提示:Qt5.5.1/Tools/QtCreator/lib/qtcreator/plugins/libHelp.so: 无法加载库
- 还是关于无法加载DLL(OCI.DLL)问题解决办法!
- 关于 lib 与dll
- 关于delphi Com+调用C# DLL的一点说明
- 关于内存加载DLL后修复重定位的问题
- Qt 动态加载 dll
- 在QT中添加.lib,.dll还有.h文件
- 在qt中调用libvlc.dll