当前位置:网站首页>The QT program compiled on CentOS lacks a MySQL driven solution

The QT program compiled on CentOS lacks a MySQL driven solution

2022-07-06 16:53:00 Flower dog fdog

I used to write a communication from client to server , Has been windows Run above , Today, I want to hang the server on the ECS for testing , One mysql The driver made me all day , Looking for a lot of information , Finally, it was solved , Make a note of , I hope I can help the people behind .

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7

Prompt unable to load driver

I think you should know it is libqsqlmysql.so The problem. , About compiling mysql Driven data , Each final solution focuses on libqsqlmysql.so This file .

If you are really the first material, click here , Then this article may help you solve the problem .

No matter what we need to download before , What to set , The ultimate essence is that we want to get libqsqlmysql.so This file

Witty, I went shopping csdn Resources for , I didn't expect that .
 Insert picture description here
This is ready-made libqsqlmysql.so Documents , Just copy it directly .

Yes , The error that prompted that the database driver could not be loaded disappeared , But don't be happy , With it comes the following error

Cannot mix incompatible Qt library (version 0x50xxx) with this library (version 0x50xxx).

So I began to solve this mistake again , After some tossing , I gave up , I know this is an error caused by the wrong version , But it can't solve , I decided to put this libqsqlmysql.so Delete , Generate a unified version based on online information libqsqlmysql.so.

Download here libqsqlmysql.so There is no problem in itself , It's just a version problem , If you qt The version of is the same as that of the resource description , I think I can try .

Let's take a look at the serious compilation to generate this file .

The first situation on the Internet is , You haven't installed it yet qt, At this time , You install qt You can choose to install the source code , I think this method is the most ridiculous , I started to compile the program before the package made this mistake , You want me to reinstall qt Do you ~~~~

The second is from the qt Official download source code , I think this method is reliable .

This is the website http://download.qt.io/archive/qt/, Find and you qt The source code package corresponding to the version .

For example, I am a 5.1.0, Then click
 Insert picture description here
 Insert picture description here

Then install a mysql Development kit
yum install mysql-devel

After downloading the source code , Remember to decompress , The order is as follows

tar -zxvf qt-everywhere-opensource-src-5.1.0.tar.gz

The unzipped folder and the compressed package are in the same place ,
 Insert picture description here

It contains four original files
 Insert picture description here
All we have to do is compile this file , notice pro Suffixed files should be familiar .

How to compile , perform qmake

If qmake The environment variables have been configured , have access to qmake command , Yes pro File for compilation , If you are prompted qmake For invalid order , You can use the following path to compile , Still in this folder directory , Find you install qt The catalog of , Such as my /opt/Qt5.1.0/5.1/gcc_64/bin, In this directory you can find qmake, Use this path pair pro Compile .
The order is as follows :
/opt/Qt5.1.0/5.1/gcc_64/bin/qmake

After execution, it will generate Makefile file

And then execute make

If it works , You see in the last output line libqsqlmysql.so Where is the file , Such as :
 Insert picture description here
If you are not familiar with this path , have access to pwd View path
 Insert picture description here
Another situation is make You don't succeed , Hint not found lmysqlclient_r

Use the find command
find /usr -name ‘*mysqlclient*’

 Insert picture description here

You can see that there is this file , Just can't find , Let's make a soft connection

sudo ln -s /usr/lib64/mysql/libmysqlclient_r.so /usr/lib/libmysqlclient_r.so

We'll do it later make There is no problem .

In fact, you can see that this file also points to libmysqlclient.so Of
 Insert picture description here

And then find qt The corresponding path
 Insert picture description here

With newly generated libqsqlmysql.so Replace this qt Self contained libqslqmysql.so You can connect to the database normally .


原网站

版权声明
本文为[Flower dog fdog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131313332760.html