您的位置:首页 > 编程语言 > Qt开发

编译ARM平台的 QtEmbedded 的MySQL插件和移植MySQL到ARM开发板

2012-05-02 11:39 375 查看
经过几天的努力,终于交叉编译出了arm平台所需Qt/E的MySQL插件(驱动),其中顺便把MySQL也移植到了mini2410的开发板上。
编译器:arm-linux-gcc(4.3.2)
Pc平台:redhat

由于mysql本身并不支持交叉编译,所以编译过程相对复杂,且各版本有所
不同,本文针对mysql-5.1.32。

1、准备工作
首先在/home/bjwlxy目录下解压mysql-5.1.32.tar.gz,得到mysql-5.1.32,进
入目录运行如下命令:
#./configure --prefix=/usr/local/mysql
# make
然后将其改名为mysql-pc备用。(注意不要# make install)

2、Configure
再次解压mysql-5.1.32.tar.gz,得到mysql-5.1.32,进入目录,修改configure
文件
#vi configure
注释以下代码:
21948#if test "$cross_compiling" = yes; then
21949# { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
21950#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
21951#{ { $as_echo "$as_me:$LINENO: error: cannot run test programwhile
crosscompiling
21952#See \`config.log' for more details." >&5
21953#$as_echo "$as_me: error: cannot run test program while crosscompiling
21954#See \`config.log' for more details." >&2;}
21955# { (exit 1); exit 1; }; }; }
21956#else
22025#fi
30317# if test "$cross_compiling" = yes; then
30318# { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
30319#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
30320#{ { $as_echo "$as_me:$LINENO: error: cannot run test programwhile
crosscompiling
30321#See \`config.log' for more details." >&5
30322#$as_echo "$as_me: error: cannot run test program while crosscompiling
30323#See \`config.log' for more details." >&2;}
30324# { (exit 1); exit 1; }; }; }
30325#else
30408#fi
保存退出。

#./configure --host=arm-linux --prefix=/usr/local/mysql

如果出现错误
error:No curses/termcap library found

再次配置
#./configure--host=arm-linux-with-named-curses-libs=/usr/lib/libncurses.so.5--prefix=/usr/local/mysql

3、Make
#make
出现错误1
/usr/lib/libncurses.so.5:could not read symbols: Invalid operationead symbols: Invalidoperation

这个是因为libncurses.so.5运行平台不是arm所致,这时,需要我们手动交叉编译libncurses.so.5文件,方法和下面的类似:

1、下载ncurses-5.6.tar.gz安装包,
#cdhome
解压包
#tarzxvf ncurses-5.6.tar.gz
#cdncurses-5.6
配置
#./configure--host=arm-linux -prefix=/usr -with-shared -without-debug
#make

2、备份/usr/lib/里面的libncurses.so.5,libncurses.so.5.6
cp/usr/lib/libncurses.so.5 /usr/lib/libncurses.so.5.bak
cp/usr/lib/libncurses.so.5.6 /usr/lib/libncurses.so.5.6.bak
复制ncurses-5.6/lib目录下交叉编译过的libncurses.so.5,libncurses.so.5.6到/usr/lib/
#cplib/libncurses.so.5 /usr/lib/
#cplib/libncurses.so.5.6 /usr/lib/
接着
#cd/home/bjwlxy/mysql-5.1.32
继续
#make
}
出现错误2
make[2]:Leaving directory `/home/zhaowg/mysql-pc/sql'
./gen_lex_hash> lex_hash.h-t
/bin/sh:./gen_lex_hash: cannot execute binary file
make[1]:*** [lex_hash.h]
错误 126
这是由于编译的arm类型的程序不能在PC上运行造成的,于是前面做的
准备工作派上用场了:
#cp ../mysql-pc/sql/gen_lex_hash sql/
#make
错误3
sql_parse.cc:5432:21:operator '<' has no left operand
make[3]:*** [sql_parse.o]
错误 1
检查 sql_parse.cc的5432行,发现宏变量STACK_DIRECTION没有定义初
值,网上查找资料发现arm中定义STACK_DIRECTION为1,于是在文件开5432的上一行
加上
#visql/sql_parse.cc
#define STACK_DIRECTION 1
保存退出。
#make
完成
4、makeinstall
#make install
会停在
makeINSTALL_TO_DIR="/usr/local/mysql/mysql-test"install_test_files
make[4]:Entering directory `/home/zhaowg/mysql-pc/mysql-test'
一段时间,不要以为出错了,耐心等一会!
到此,编译arm平台的mysql基本完成。

编译arm平台的QtEmbeddedmysql插件
进入Qt/E目录
#cd $QTDIR/src/plugins/sqldrivers/mysql
#qmake "INCLUDEPATH+=/usr/local/mysql/include/mysql""LIBS+=-L/usr/local/mysql/lib/mysql
-lmysqlclient_r"mysql.pro
#make
#makeinstall
#cd$QTDIR/plugins/sqldrivers/
#ls
如果出现libqsqlite.so,说明编译成功。

移植MySQL到开发板
将/usr/local目录下的mysql文件夹拷贝到开发板的/usr/local目录下,并在环
境变量里面声明。
#export PATH=”$PATH:/usr/local/mysql/bin”
6、开启mysqld服务
首先将以下内容保存为/etc/my.conf
[mysqld]
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
user=root
#Default to using old password format for compatibility with mysql 3.x
#clients (those using the mysqlclient10 compatibility package).
old_passwords=1
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
因为在/var/run目录下没有mysqld/mysqld.pid,手工建立:
#mkdir /var/run/mysqld
#touch /var/run/mysqld/mysqld.pid
开启服务:
#mysql_install_db –u root
#mysqld_safe –socket=/tmp/mysql.sock &
至此,mysql运行在arm
开发板上了

以下是我做的在arm上的移植:
因为登陆不上!
 mysqld_safe --user=root --skip-grant-tables --skip-networking &
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息