您的位置:首页 > 编程语言 > Qt开发

关于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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: