windows c++ 项目移植到 linux,原项目需要连接 Firebird数据库。
google 后知道 linux qt connection Firebird 有两种方法:
- 1.ibpp connection firebird;
- 2.QSqlDatabase: QIBASE driver connection Firebird;
Linux 环境编译libqsqlibase.so
- 安装Centos7.2 桌面、安装qt5.5 ;
- Install GCC Compiler on CentOS7
sudo yum group install "Development Tools"
sudo yum install man-pages
gcc --version
报:QSqlDatabase: QIBASE driver not loaded 需要自己编译 QIBASE driver 生成libqsqlibase.so
- 参考下面方法
https://forum.qt.io/search?term=libqsqlibase.so&in=posts&matchWords=all&sortBy=relevance&sortDirection=desc&showAs=posts
- 毕竟环境和网上不完全一样,可能会遇到一些问题。
[root@Desk001 ~]# find / -name ibase
/opt/Qt5.5.1/5.5/Src/qtbase/src/plugins/sqldrivers/ibase
/opt/Qt5.5.1/5.5/Src/qtbase/src/sql/drivers/ibase
/opt/Qt5.5.1/5.5/Src/qtbase/config.tests/unix/ibase
[root@Desk001 ~]# cd /opt/Qt5.5.1/5.5/Src/qtbase/src/plugins/sqldrivers/ibase
[root@Desk001 ibase]# /opt/Qt5.5.1/5.5/gcc_64/bin/qmake ibase.pro
[root@Desk001 ibase]# ll
total 60
-rwxrwxr-x. 1 root root 29 Oct 13 2015 ibase.json
-rwxrwxr-x. 1 root root 187 Dec 16 22:50 ibase.pro
-rwxrwxr-x. 1 root root 2254 Oct 13 2015 main.cpp
-rw-r--r--. 1 root root 46701 Dec 16 23:09 Makefile
[root@Desk001 ibase]# chmod 775 Makefile
[root@Desk001 ibase]# make
报错
../../../sql/drivers/ibase/qsql_ibase_p.h:50:19: fatal error: ibase.h: No such file or directory
#include <ibase.h>
报错 /usr/bin/ld: cannot find -lgds
[root@Desk001 ibase]# ln -s /usr/lib64/libfbclient.so.2.5.9 /usr/lib64/libgds.so
- 缺失头文件官网下载;
- ibpp官网地址
4.make make install、
[root@Desk001 ibase]# cd /opt/Qt5.5.1/5.5/Src/qtbase/src/plugins/sqldrivers/ibase
[root@Desk001 ibase]# ll
total 64
-rwxrwxr-x. 1 root root 29 Oct 13 2015 ibase.json
-rwxrwxr-x. 1 root root 187 Dec 16 22:50 ibase.pro
drwxr-xr-x. 5 root root 4096 Dec 16 23:33 ibpp
-rwxrwxr-x. 1 root root 2254 Oct 13 2015 main.cpp
-rwxrwxr-x. 1 root root 46701 Dec 16 23:09 Makefile
[root@Desk001 ibase]# make
......
[root@Desk001 ibase]# make install
install -m 755 -p ../../../../plugins/sqldrivers/libqsqlibase.so /opt/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/libqsqlibase.so
strip --strip-unneeded /opt/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers/libqsqlibase.so
install -m 644 -p /opt/Qt5.5.1/5.5/Src/qtbase/lib/cmake/Qt5Sql/Qt5Sql_QIBaseDriverPlugin.cmake /opt/Qt5.5.1/5.5/gcc_64/lib/cmake/Qt5S
ql/
[root@Desk001 apps]# cd /opt/Qt5.5.1/5.5/gcc_64/plugins/sqldrivers
[root@Desk001 sqldrivers]# ll
total 1076
-rwxr-xr-x. 1 root root 102168 Dec 16 23:57 libqsqlibase.so
-rwxr-xr-x. 1 root root 838064 Oct 13 2015 libqsqlite.so
-rwxr-xr-x. 1 root root 75504 Oct 13 2015 libqsqlmysql.so
-rwxr-xr-x. 1 root root 79248 Oct 13 2015 libqsqlpsql.so
Windos 环境编译 ibase
参考
https://forum.qt.io/topic/26620/how-to-build-plugin-qibase-for-firebird-qt-5-0-2/4
- 安装qt5.5、配置qt环境变量,安装FireBird2.5(32位)(软件版本按自己需求选)。
- 修改 F:\ProgramFiles\qt5.5\5.5\Src\qtbase\src\plugins\sqldrivers\ibase\ibase.pro
添加FireBird数据库include
TARGET = qsqlibase
SOURCES = main.cpp
OTHER_FILES += ibase.json
INCLUDEPATH += C:/Firebird/Firebird_2_5/include
LIBS += C:/Firebird/Firebird_2_5/lib/fbclient_ms.lib
include(../../../sql/drivers/ibase/qsql_ibase.pri)
PLUGIN_CLASS_NAME = QIBaseDriverPlugin
include(../qsqldriverbase.pri)
- 编译
qmake ibase.pro
mingw32-make(有报头文件 ibase.h 找不到)
修改 F:\ProgramFiles\qt5.5\5.5\Src\qtbase\src\sql\drivers\ibase\qsql_ibase_p.h
添加
#include <ibase.h>
修改F:\ProgramFiles\qt5.5\5.5\Src\qtbase\src\plugins\sqldrivers\ibase\main.cpp
添加
#include "../../../sql/drivers/ibase/qsql_ibase_p.h"
然后重新编译
mingw32-make
Win环境 使用FireBird
a.本机安装数据库服务情况下直接使用;
b.本机不安装数据库服务情况下,可以访问远程数据库(网络模式);
- firebird官网下载 32-bit Classic, Superclassic & Superserver,安装。
- 安装完成后把 bin目录下的fbclient.dll 放到工程编译后生成的exe同级目录
c.本机不启用数据库服务情况下,可以访问本机数据库文件(嵌入式模式)。 - firebird官网下载 32-bit Embedded。
- 解压后把fbembed.dll改成fbclient.dll 放到工程编译后生成的exe同级目录
- 参考
Client and server combined: Firebird Embedded Server 嵌入式文档