qt中怎样添加库文件?

qt中怎样添加库文件?,第1张

相信很多人有这样的需求吧 推荐使用 Qt Creator 2.1 以上版本,因为自带了 Class View ,不需要第三方的插件就可以看Symbol了。

新建项目里,选择 Other Project 然后是 Import Existing Project,建立项目后添加文件,最后需要的是自己写一个 Makefile, 而且默认的 Build 目标是 all,注意 GNU make 的文件格式,命令行开头需要一个完整的 TAB 针对最简单的单文件,比如 main.cpp ,makefile 可以这样写 all: g++ -o main main.cpp 然后就可以了。

如果你自己添加的第三方库也可以提供自动补全功能,但是需要能搜索到这个库目录,我用的是 Mingw ,直接把第三方库放到 Mingw 对应的 include 和 lib 目录了,引用头文件之后自动补全很好很强大。应该也有环境变量来设置的,不过暂时不大清楚如何 *** 作。 工具->选项->项目和解决方案  之后窗口右上方 “显示以下文件的目录”  默认是可执行文件

把它修改成“库文件” 就可以添加了。

.pro文件管理,所以库文件要在.pro文件中添加。1.添加库文件静态库linux:LIBS += your_lib_path/your_lib动态库linux:LIBS += -L your_lib_path -lyour_lib//经过测试了win32:LIBS += your_lib_path/your_lib例如:LIBS += -L lib/pcsc/ -lpcscliteLIBS += lib/pcsc/libpcsclite.a2.添加头文件INCLUDEPATH += your_include_path例如:INCLUDEPATH += . /usr/local/include(点号后面有空格)3.添加要编译的源文件和头文件SOURCES:所有源文件列表HEADERS:所有头文件列表FORMS:所有.ui文件列表前期工作:1.检查gcc,g++,qmake是否用错。2.在Makefile中检查是否少了头文件3.检查是否与<错用了4.需要另外加库的程序最好单独建一个文件

之前项目里使用其它的第三方库都是leader或同事给配置好的,从没 *** 心这回事,真是惭愧,。今天同学给我发来一个工程,需用使用到Qt库和Qwt库,用QtCreator打开编译,提示找不到Qwt库里的头文件,于是试着配置一下,居然折腾了许久还没运行起来。后来看了一下Qt的qmake文档,才得以搞定。qmake 的说明文档里有关于声明使用其它库的说明:

Declaring Other Libraries

If you are using other libraries in your project in addition to those supplied with Qt, you need to specify them in your project file.

The paths that qmake searches for libraries and the specific libraries to link against can be added to the list of values in the LIBS variable. The paths to the libraries themselves can be given, or the familiar Unix-style notation for specifying libraries and paths can be used if preferred.

For example, the following lines show how a library can be specified:

[cpp] view plain copy

LIBS += -L/usr/local/lib -lmath

The paths containing header files can also be specified in a similar way using the INCLUDEPATH variable.

For example, it is possible to add several paths to be searched for header files:

[cpp] view plain copy

INCLUDEPATH = c:/msdev/include d:/stl/include

如果电脑上已经安装了Qt 和Qwt的环境,那么对于一个需要使用Qwt的程序来说,只需要在其工程文件中添加如下配置:

(假设你的Qwt安装目录为 C:/Qwt-6.0.1 )

1)在 LIBS 变量后面添加链接这个库的路径(例如-LC:/Qwt-6.0.1/lib)和名称(例如 -lqwt, 也可以用 qtAddLibrary(qwt) 添加动态库)

2)在INCLUDEPATH variable.后面添加这个引用该库所需要的头文件(例如 C:/Qwt-6.0.1/include)

[cpp] view plain copy

#include( $${PWD}/../examples.pri )

#include( ../3rdparty/qwt/qwtplot.pri )

#include( C:/Qwt-6.0.1/features/qwtconfig.pri )

INCLUDEPATH += C:/Qwt-6.0.1/include #必须有

#DEPENDPATH += C:/Qwt-6.0.1/lib

#LIBS += -L/usr/local/lib -lmath

LIBS += -LC:/Qwt-6.0.1/lib -lqwt #必须有 否则报错 :-1: error: cannot find -lqwt

#qtAddLibrary(qwt) #必须有

#CONFIG += qwt


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11940713.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存