摘要
为了使用在arch64机子上使用qt的mysql驱动而进行的对mysql源码的交叉编译,对libqsqlmysql.so驱动的安装
环境
host
系统(虚拟机):
target
系统:
是什么
交叉编译:在本文中指的是,在host(x86_64架构的虚拟机)中编译出可以在target(aarch64架构的机子)上可执行的程序。
交叉编译mysql:在本文中指的是,在host中用交叉编译器编译mysql源码,生成可以在target上使用的动态库。
为什么
在aarch64机子上装了mysql,其版本信息如下。
交叉编译mysql是为了生成libmysqlclient.a和libmysqlclient.so。qt的源码会用这个库来编译出mysql驱动libqsqlmysql.so。把libqsqlmysql.so和libmysqlclient.so拷贝到target中后,交叉编译出来的qt程序就可以通过驱动libqsqlmysql.so调用libmysqlclient.so,libmysqlclient.so操作mysql数据库,来完成crud操作。
怎么做
方法1
不交叉编译mysql。
如果target能联网,其实不用交叉编译mysql。可以用apt-get命令下载到需要的libqsqlmysql.so和libmysqlclient.so。在下就是用这个方法解决的问题。
交叉编译qt,配置编译套件
参考这个帖子
已经交叉编译了qt5.12.10,配置了gcc、g++、gdb。顺便一提gdb-multiarch的版本和qtcreator的版本如下图所示。
安装mysql驱动
已经用qt写完代码,交叉编译出了一个名字是testInsertData2Base的程序,这个程序是用来测试向mysql数据库插入数据的,在target上运行时提示缺少动态库libQt5Sql.so.5。
用下图的命令搜索相关的动态库。
从搜索结果中看出该执行下图命令来安装libQt5Sql.so.5。
安装完成之后可以用find指令找到动态库的绝对路径。问:为啥要找这个动态库的绝对路径?答:不为啥,我就是想看看安装了没。
搜索结果中不仅有libQt5Sql.so.5,而且还有mysql驱动。
像安装libQt5Sql.so.5一样安装mysql驱动后,使用ldd查看mysql驱动依赖的动态库。
mysql驱动依赖libmysqlclient.so.21这个动态库,如果这个动态库右边提示not found,那就需要再搜索,安装libmysqlclient.so.21这个库。
安装完成之后,testInsertData2Base依赖的动态库都能找到,就可以运行testInsertData2Base这个程序了。
方法2
交叉编译mysql源码。
在下虽然交叉编译了mysql8.0.22,编译出了mysql驱动,但最后碰到了这个问题。
# 往数据库写数据库时提示没有加载mysql的驱动,但是可用的驱动中又有mysql
https://myprogrammingnotes.com/qsqldatabase-qmysql-driver-loaded.html
# 读了上面这个帖子,发现原来是还需要libmysqlclient库,但是交叉编译mysql生成libmysqlclient库和target里已有的qt库版本不兼容。所以方法2最终并没有完成对mysql数据库的操作。
安装交叉编译工具
参考链接
下载mysql-boost
MySQL :: Download MySQL Community Server (Archived Versions)
# 下载mysql-boost-8.0.22.tar.gz
mysql交叉编译方式_mysql 交叉编译_Lanceli_van的博客-CSDN博客
交叉编译mysql-8.0.22 最新版本_shenkaibo的博客-CSDN博客
# 参考的教程地址
编译x86版本的mysql,安装
解压 mysql-boost-8.0.22 压缩包,进入文件夹第一层目录,输入以下命令:
mkdir build_x86
cd build_x86
cmake .. -DWITH_BOOST=/home/user/Downloads/mysql-8.0.22/boost -DCMAKE_INSTALL_PREFIX=/home/user/mysql-8.0.22/__install
# 不下载不boost,boost在/home/user/Downloads/mysql-8.0.22/boost
# 安装x86_64版本的mysql到/home/user/mysql-8.0.22/__install
make -j4
# 编译x86_64版本的mysql
make install
// 安装
交叉编译ncurses,安装
# 下载ncurses-6.2.tar.gz
进入解压后的文件夹,执行
./configure --prefix=/home/user/ncurses-6.2/__install --host=aarch64-linux CC=aarch64-linux-gnu-gcc --with-shared --without-progs
./configure 的用法_./configure --host_战国沙琪玛的博客-CSDN博客
# --host是编译的前两个词
make -j4
# 编译
make install
# 安装
交叉编译openssl,安装
各类源码下载网址(u-boot,linux,openssl,文件系统) - 嵌入式Linux知识共享 - 博客园 (cnblogs.com)
/source/index.html (openssl.org)
# 下载openssl-1.1.1g.tar.gz
进入解压后的文件夹,执行
./config --prefix=/home/user/openssl-OpenSSL_1_1_1g/__install --cross-compile-prefix=aarch64-linux-gnu- no-asm shared
make -j4
make install
出现错误:
aarch64-linux-gnu-gcc: error: unrecognized command line option '-m64'
解决方法:
交叉编译openssl到aarch64 - 灰信网(软件开发博客聚合) (freesion.com)
# 删除Makefile 里面的 -m64
交叉编译boost,安装
# 下载boost_1_73_0.tar.gz
解压,进入文件夹,执行
# ./bootstrap.sh --prefix=/home/user/boost_1_73_0/__install
修改 project-config.jam
if ! gcc in [ feature.values <toolset> ]
{
using gcc : : /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc ;
}
# ./b2
# ./b2 install
交叉编译mysql8.0.22
修改CMakeLists.txt
修改libevent.cmake
mysql交叉编译方式_mysql 交叉编译_Lanceli_van的博客-CSDN博客
# 参考链接
错误:
-- Downloading boost_1_73_0.tar.gz to /home/user/mysql-8.0.22_arm64/boost
-- Download failed, error: 22;"HTTP response code said error"
CMake Error at cmake/boost.cmake:232 (MESSAGE):
You can try downloading
https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.gz
manually using curl/wget or a similar tool
Call Stack (most recent call first):
CMakeLists.txt:1181 (INCLUDE)
// 在给定的网址下载不到boost
解决:
修改boost.cmake中的下载地址
# https://boostorg.jfrog.io/artifactory/main/release/1.73.0/source/boost_1_73_0.tar.gz
错误:
No package 'libtirpc' found
解决:
libtirpc-1.3.3 (linuxfromscratch.org)
# 下载 libtirpc-1.3.3.tar.bz2
# 安装
交叉编译
# 先执行cmake,参数如下(如果不会科学上网就试不下载boost)
user@user-virtual-machine:~/Downloads/mysql-8.0.22/build_arm64$ cmake .. -DDOWNLOAD_BOOST=1 -DENABLE_DOWNLOADS=1 -DWITH_BOOST=/home/user/mysql-8.0.22_arm64/boost -DCMAKE_INSTALL_PREFIX=/home/user/mysql-8.0.22_arm64/__install -DCURSES_INCLUDE_PATH=/home/user/ncurses-6.2/__install/include -DCURSES_LIBRARY=/home/user/ncurses-6.2/__install/lib/libncurses.so -DSTACK_DIRECTION=1 -DWITH_LIBEVENT="bundled" -DRESOLV_LIBRARY=/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/usr/lib/libresolv.so
# 然后编译
make -j4
错误:
/bin/sh: 1: comp_err: not found
解决:
user@user-virtual-machine:~/Downloads/mysql-8.0.22/extra$ sudo cp /home/user/mysql-8.0.22/__install/bin/comp_err /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/
错误:
/bin/sh: 1: comp_sql: not found
解决:
user@user-virtual-machine:~/Downloads$ sudo cp /home/user/Downloads/mysql-8.0.22/build_x86/runtime_output_directory/comp_sql /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/
错误:
/home/user/Downloads/mysql-8.0.22/storage/innobase/include/os0atomic.ic:194:2: error: #error "Unsupported platform"
#error "Unsupported platform"
解决:
mysql8 安装 - 青色蔷薇 - 博客园 (cnblogs.com)
# 修改os0atomic.ic和os0atomic.h
错误:
/bin/sh: 1: uca9dump: not found
解决:
user@user-virtual-machine:~/Downloads$ sudo cp /home/user/Downloads/mysql-8.0.22/build_x86/runtime_output_directory/uca9dump /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/
错误:
/bin/sh: 1: gen_lex_hash: not found
解决:
user@user-virtual-machine:~/Downloads$ sudo cp /home/user/Downloads/mysql-8.0.22/build_x86/runtime_output_directory/gen_lex_hash /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/
错误:
/bin/sh: 1: json_schema_embedder: not found
解决:
user@user-virtual-machine:~/Downloads$ sudo cp /home/user/Downloads/mysql-8.0.22/build_x86/router/src/json_schema_embedder/json_schema_embedder /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/
错误:
/bin/sh: 1: gen_keyword_list: not found
解决:
user@user-virtual-machine:~/Downloads$ sudo cp /home/user/Downloads/mysql-8.0.22/build_x86/runtime_output_directory/gen_keyword_list /opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/
错误:
/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/7.5.0/../../../../aarch64-linux-gnu/bin/ld: cannot find -ltirpc
collect2: error: ld returned 1 exit status
make[2]: *** [plugin/group_replication/CMakeFiles/group_replication.dir/build.make:1304: plugin_output_directory/group_replication.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:7279: plugin/group_replication/CMakeFiles/group_replication.dir/all] Error 2
解决:
# 35个link.txt里面有-ltirpc