举个例子,就容易理解了。
//libmy.h
#ifndef LIBMY_H
#define LIBMY_H
#include
class MyLib : public QObject
{
public:
MyLib();
~MyLib();
void hello();
};
#endif /*LIBMY_H*/
//libmy.cpp
#include "libmy.h"
#include
MyLib::MyLib()
{
}
MyLib::~MyLib()
{
}
void MyLib::hello()
{
qDebug() << "hello world~!";
}
//libmy.pro
######################################################################
# Automatically generated by qmake (2.01a) ?? 11? 7 17:17:14 2012
######################################################################
TEMPLATE = lib
TARGET = my
DEPENDPATH += . src
INCLUDEPATH += . src
# Input
HEADERS += src/libmy.h
SOURCES += src/libmy.cpp
//libmy.pc
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/
Name: libmy
Description: libmy test
Version: 0.1
Requires:
Libs: -L${libdir} -lmy
Cflags: -I${includedir}
以上是编写库的demo
//main.cpp
#include "libmy.h"
#include
int main(int argc,char *argv[])
{
QApplication app(argc,argv);
MyLib *lib = new MyLib();
lib->hello();
app.exec();
return 0;
}
在main.cpp的pro文件中,添加
CONFIG += link_pkgconfig
PKGCONFIG += libmy
连接到刚才编译的libmy库,
取消
评论