Cross Compile Mysql _ Messy, but seems to work.

483 views
Skip to first unread message

adam jvok

unread,
Feb 17, 2010, 12:27:39 AM2/17/10
to dealextr...@googlegroups.com
A few weeks ago I posted about cross-compiling using http://freshmeat.net/projects/crosstool-ng/
Douglas replied, pointing me toward http://cnusers.org
I've just tried this, and believe me, cnusers will make your life a lot easier (at least on this platform) than crosstool-ng.
Thanks for the pointer, Douglas.

So next, trying to do something useful I attempted to cross-compile MySQL.
This is now working.
I'm posting my steps below in the hope that:
(i) someone can advise how to do this better;
(ii) it may, possibly, help someone else.

Here we go:

1. Setup the cross-compiler tool chain:
============================
Register with http://cnusers.org .
mkdir $HOME/cnusers
cd $HOME/cnusers
download CNS2100-LSDK-6.8.2.zip to $HOME/cnusers
unzip CNS2100-LSDK-6.8.2.zip
cd CNS2100-LSDK-6.8.2
bunzip2 CNS2100-LSDK-6.8.2.tar.bz2
tar xvf CNS2100-LSDK-6.8.2.tar

2. Build MySQL.
============
cd $HOME/cnusers
Download the source from http://dev.mysql.com/downloads/mirror.php?id=382175#mirrors e.g.
wget http://mysql.ntu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.43.tar.gz
tar xvzf mysql-5.1.43.tar.gz

Oddity #1: it seems to need a program called 'gen_lex_hash' (in the 'sql' dir), built for the build-os (not for the cross-compiled, target-os) in order for the cross-compile to succeed. So, first build this:
./configure
make
cp sql/gen_lex_hash ../
[There must be a better way of doing this?]
cd ..
[ I remove everything because I couldn't see how to clean up from the ./configure without doing a complete remove]
rm -rf mysql-5.1.43
tar xvzf mysql-5.1.43.tar.gz
cd mysql-5.1.43

Make sure that the cnusers tools are in the PATH:

export PATH=$PATH:$HOME/cnusers/CNS2100-LSDK-6.8.2/CNS2100-LSDK-6.8.2/tools/arm-uclibc-3.4.6/bin

If you now run "./configure --host=arm-linux-uclibc" you will experience a string of problems. I found that these next steps solved those issues, so don't './configure' just yet.

Oddity #2 - the configure script complains that it can't perform several tests when cross-compiling. To overcome this I hack the script like this:

sed -i '/# either define HAVE_IB_GCC_ATOMIC_BUILTINS or not/{n; s/yes/hack/}' configure
sed -i '/# either define HAVE_IB_ATOMIC_PTHREAD_T_GCC or not/{n; s/yes/hack/}' configure
sed -i '/# either define HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS or not/{n; s/yes/hack/}' configure

[Note: while these steps help with the build, I have no idea what the run-time consequences are.]

Now for the configure (the 'ac_cv_sys_restartable_syscalls=yes' overcomes yet another configure issue):

./configure --host=arm-linux-uclibc --with-low-memory ac_cv_sys_restartable_syscalls=yes

Oddity #3: To avoid one more issue:
sed 's/#ifndef \(STACK_DIRECTION\)/#define \1 1\n#ifndef \1/'  -i include/my_global.h
[could possibly do this using CPPFLAGS, and avoid this step, but I don't have the time to figure it out.]

make

.. which will fail, complaining about gen_lex_hash

cp ../gen_lex_hash sql/
make

... and that appears to have built it.

3. Install
======
Here, I'm just copying the least stuff I need to get the thing running.

I expect that there is a nice easy way of doing some sort of 'make install', copying everything needed over to snake [someone please tell me], but I've missed it.

All commands that are performed on the snake box are show below starting with '$', otherwise they are done from my desktop.

Install is going on usb drive attached to SnakeOs. /usb/sda1

Set a variable that is the IP of your snake box:
export snake=192.168.1.3
[This is used by the scp commands below. I used scp because I was doing it a file at a time, while figuring out what was needed, but it might be eaier just to move the drive from snake to your desktop and then just 'cp'.]

$ adduser -g mysql mysql
$ mkdir /usb/sda1/lib
scp $HOME/cnusers/CNS2100-LSDK-6.8.2/CNS2100-LSDK-6.8.2/tools/arm-uclibc-3.4.6/lib/libncurses.so.5 root@$snake:/usb/sda1/lib/
scp $HOME/cnusers/CNS2100-LSDK-6.8.2/CNS2100-LSDK-6.8.2/tools/arm-uclibc-3.4.6/lib/libstdc++.so.6 root@$snake:/usb/sda1/lib/


$ export LD_LIBRARY_PATH=/usb/sda1/lib

$ mkdir /usb/sda1/mysql/mysqldat
$ mkdir /usb/sda1/mysql/bin
$ mkdir -p /usb/sda1/mysql/share/mysql/english
scp  ./sql/share/english/errmsg.sys  root@$snake:/usb/sda1/mysql/share/mysql/english/
scp ./extra/resolveip root@$snake:/usb/sda1/mysql/bin/
scp ./extra/my_print_defaults root@$snake:/usb/sda1/mysql/bin/
scp ./scripts/mysql_install_db root@$snake:/usb/sda1/mysql/bin/
scp ./sql/mysqld root@$snake:/usb/sda1/mysql/bin/
scp  ./scripts/fill_help_tables.sql  root@$snake:/usb/sda1/mysql/share/
scp  ./scripts/mysql_system_tables.sql  root@snake:/usb/sda1/mysql/share/
scp  ./scripts/mysql_system_tables_data.sql   root@$snake:/usb/sda1/mysql/share/
scp  ./client/.libs/mysqladmin   root@$snake:/usb/sda1/mysql/bin/
scp  ./client/.libs/mysql   root@$snake:/usb/sda1/mysql/bin/
scp ./libmysql/.libs/libmysqlclient.so.16 root@$snake:/usb/sda1/lib/

$ /usb/sda1/mysql/bin/mysql_install_db --datadir=/usb/sda1/mysql/mysqldat --user=root --basedir=/usb/sda1/mysql

Now for something nasty: I want the 'mysql' user to own everything under /usb/sda1/mysql, but I didn't think about this earlier and my usb disk is still using the factory supplied FAT32 partition, so:
$chown -R mysql.mysql /usb/sda1/mysql
fails with: Operation not permitted
It should be OK on an ext2/3 partition.
For me, I did this nasty:
$ chmod -r 777 /usb/sda1/mysql
[I'll come back mkfs my usb drive later.]

Now start the server:
$ /usb/sda1/mysql/bin/mysqld --datadir=/usb/sda1/mysql/mysqldat --user=mysql --basedir=/usb/sda1/mysql &

Set the root password:
$ /usb/sda1/mysql/bin/mysqladmin -u root password 'abc'

Now connect to the server with a client program:
$ /usb/sda1/mysql/bin/mysql -uroot -pabc 
mysql> create database mytest;
mysql> use mytest; 
mysql> grant all on mytest.* to newuser@'%' ;
mysql> set password for newuser@'%'=password('123');
mysql> exit;

From my desktop I can connect to the snakeos mysql with:
mysql -h $snake -unewuser -p123 -Dmytest

4. Comments
==========
1. I need a better way of started mysqld (mysqld_safe?) ... and stopping.
2. Various other utilities need to be copied across from the build directories.
3. Warning...
*************************************************************************************
**********************WARNING***************************************************
*************************************************************************************
The above is all I've done - just managed to build and start the server.
I have no idea if this will be stable, or suitable for any real use.
Try at you own risk.
*************************************************************************************

I hope that helps someone else.
Any suggestion on how to improve will be appreciated.

Khirs

unread,
Feb 17, 2010, 1:58:33 PM2/17/10
to DealExtreme NAS
Thanks for your info.
I try compiled amuled with your "method".
Besgards
Khirs

On Feb 17, 6:27 am, adam jvok <ajv...@gmail.com> wrote:
> A few weeks ago I posted about cross-compiling usinghttp://freshmeat.net/projects/crosstool-ng/<http://www.google.com/url?sa=D&q=http://freshmeat.net/projects/crosst...>
> Douglas replied, pointing me towardhttp://cnusers.org<http://www.google.com/url?sa=D&q=http://cnusers.org&usg=AFQjCNFNMQV-E...>


> I've just tried this, and believe me, cnusers will make your life a lot
> easier (at least on this platform) than crosstool-ng.
> Thanks for the pointer, Douglas.
>
> So next, trying to do something useful I attempted to cross-compile MySQL.
> This is now working.
> I'm posting my steps below in the hope that:
> (i) someone can advise how to do this better;
> (ii) it may, possibly, help someone else.
>
> Here we go:
>
> 1. Setup the cross-compiler tool chain:
> ============================

> Register withhttp://cnusers.org<http://www.google.com/url?sa=D&q=http://cnusers.org&usg=AFQjCNFNMQV-E...>.


> mkdir $HOME/cnusers
> cd $HOME/cnusers
> download CNS2100-LSDK-6.8.2.zip to $HOME/cnusers
> unzip CNS2100-LSDK-6.8.2.zip
> cd CNS2100-LSDK-6.8.2
> bunzip2 CNS2100-LSDK-6.8.2.tar.bz2
> tar xvf CNS2100-LSDK-6.8.2.tar
>
> 2. Build MySQL.
> ============
> cd $HOME/cnusers
> Download the source fromhttp://dev.mysql.com/downloads/mirror.php?id=382175#mirrorse.g.

> wgethttp://mysql.ntu.edu.tw/Downloads/MySQL-5.1/mysql-5.1.43.tar.gz

Khirs

unread,
Feb 17, 2010, 3:41:03 PM2/17/10
to DealExtreme NAS
I have the first error.
Compile wxWidgets with this options:
./configure --host=arm-linux --prefix=/home/operador/cnusers/
wxwidgets/wxWidgets-2.8.10/compilado/ --enable-unicode --enable-
optimise --disable-gui
This is correct.

But when i do:
make
Have this error:

/home/operador/cnusers/CNS2100-LSDK-6.8.2/CNS2100-LSDK-6.8.2/tools/arm-
uclibc-3.4.6/bin/../lib/gcc/arm-linux-uclibc/3.4.6/../../../../arm-
linux-uclibc/bin/ld: basedll_appbase.o: Relocations in generic ELF
(EM: 3)
/home/operador/cnusers/CNS2100-LSDK-6.8.2/CNS2100-LSDK-6.8.2/tools/arm-
uclibc-3.4.6/bin/../lib/gcc/arm-linux-uclibc/3.4.6/../../../../arm-
linux-uclibc/bin/ld: basedll_appbase.o: Relocations in generic ELF
(EM: 3)
/home/operador/cnusers/CNS2100-LSDK-6.8.2/CNS2100-LSDK-6.8.2/tools/arm-
uclibc-3.4.6/bin/../lib/gcc/arm-linux-uclibc/3.4.6/../../../../arm-
linux-uclibc/bin/ld: basedll_appbase.o: Relocations in generic ELF
(EM: 3)
/home/operador/cnusers/CNS2100-LSDK-6.8.2/CNS2100-LSDK-6.8.2/tools/arm-
uclibc-3.4.6/bin/../lib/gcc/arm-linux-uclibc/3.4.6/../../../../arm-
linux-uclibc/bin/ld: basedll_appbase.o: Relocations in generic ELF
(EM: 3)
/home/operador/cnusers/CNS2100-LSDK-6.8.2/CNS2100-LSDK-6.8.2/tools/arm-
uclibc-3.4.6/bin/../lib/gcc/arm-linux-uclibc/3.4.6/../../../../arm-
linux-uclibc/bin/ld: basedll_appbase.o: Relocations in generic ELF
(EM: 3)
basedll_appbase.o: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make: *** [/home/operador/cnusers/wxwidgets/wxWidgets-2.8.10/lib/
libwx_baseu-2.8.so.0.6.0] Error 1

Everyone have a solutión?

Jan Horak

unread,
Feb 17, 2010, 5:08:05 PM2/17/10
to dealextr...@googlegroups.com
Did you try to build amuled with x86 gcc before? If so you have to
make clean sources before compile for arm or delete whole package,
unpack source tarball and try again only with CNS sdk.

> --
> You received this message because you are subscribed to the Google
> Groups "DealExtreme NAS" group.
> To post to this group, send email to dealextr...@googlegroups.com
> To unsubscribe from this group, send email to
> dealextreme-na...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/dealextreme-nas-?hl=en

--
jh

Khirs

unread,
Feb 17, 2010, 5:41:46 PM2/17/10
to DealExtreme NAS
I try the new and now fail in configure:
I execute:
./configure --host=arm-linux-uclibc --prefix=/home/operador/cnusers/

wxwidgets/wxWidgets-2.8.10/compilado/ --enable-unicode --enable-
optimise --disable-gui

And have this error:

hecking whether we are using the GNU C compiler... yes
checking whether arm-linux-uclibc-gcc accepts -g... yes
checking for arm-linux-uclibc-gcc option to accept ANSI C... none
needed
checking if the C compiler requires -ext o...
checking whether we are using the Metrowerks C compiler... no
checking whether we are using the IBM xlC C compiler... no
checking build system type... i686-pc-linux-gnu
checking host system type... Invalid configuration `arm-linux-uclibc':
system `uclibc' not recognized
configure: error: /bin/bash conftools/config.sub arm-linux-uclibc
failed
configure: error: /bin/bash './configure' failed for src/expat

> ...
>
> read more »

Reply all
Reply to author
Forward
0 new messages