OpenWrt Forum Archive

Topic: cross compile with libmysql

The content of this topic has been archived on 15 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello to everybody,

i am developing some C code to be used on OpenWRT.
Until now, it is just accessing UART so a simple cross compile from my Ubuntu machine is working.

I have exported all the necessary paths and i just run:

mips-openwrt-linux-gcc -o hello-world  hello-world.c

I would like now to access a mysql database so i am just trying how to deal with mysql C API.

I have this simple C code:

#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv)
{
  printf("MySQL client version: %s\n", mysql_get_client_info());

  exit(0);
}

Which of course compiled on my x86 machine is perfectly working but as soon as i cross compile it, i get:

root@linux01:~/mysql-example# mips-openwrt-linux-gcc -o mysql-test  mysql-test.c
mysql-test.c:1:23: fatal error: my_global.h: No such file or directory
 #include <my_global.h>
                       ^
compilation terminated.

That is quite clear...i need to tell to gcc where to get mysql headers file....but i do not know how to get them for openwrt.....

can somebody help me ?

Thanks
Ettore

I build OpenWRT from GIT trunk source. This means the build process will build everything, including toolchain staged at <OpenWRT source root directory>/staging/toolchain-<target platform> and target libraries at <OpenWRT source root directory>/staging/target-<target platform>. So, in order to manually compile your MySQL example code above, I did the following to produce the binary executable file:

[debian@debian:/opt/openwrt-git-trunk.2 478%] ~ /opt/openwrt-git-trunk/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-1.0.9_eabi/bin/arm-openwrt-linux-uclibcgnueabi-gcc -I/opt/openwrt-git-trunk/staging_dir/target-arm_mpcore_uClibc-1.0.9_eabi/usr/include/mysql -o /tmp/mysql_test /tmp/mysql_test.c -L/opt/openwrt-git-trunk/staging_dir/target-arm_mpcore_uClibc-1.0.9_eabi/usr/lib/ -lmysqlclient
In file included from /tmp/mysql_test.c:1:0:
/opt/openwrt-git-trunk/staging_dir/target-arm_mpcore_uClibc-1.0.9_eabi/usr/include/mysql/my_global.h:897:0: warning: "isnan" redefined [enabled by default]
 #define isnan(x) ((x) != (x))
 ^
In file included from /opt/openwrt-git-trunk/staging_dir/target-arm_mpcore_uClibc-1.0.9_eabi/usr/include/mysql/my_global.h:426:0,
                 from /tmp/mysql_test.c:1:
/opt/openwrt-git-trunk/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-1.0.9_eabi/include/math.h:281:0: note: this is the location of the previous definition
 #  define isnan(x) \
 ^
/opt/openwrt-git-trunk/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-1.0.9_eabi/lib/gcc/arm-openwrt-linux-uclibcgnueabi/4.8.3/../../../../arm-openwrt-linux-uclibcgnueabi/bin/ld: cannot find -lmysqlclient
collect2: error: ld returned 1 exit status
[debian@debian:/opt/openwrt-git-trunk.2 479%] ~ /opt/openwrt-git-trunk/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-1.0.9_eabi/bin/arm-openwrt-linux-uclibcgnueabi-gcc -I/opt/openwrt-git-trunk/staging_dir/target-arm_mpcore_uClibc-1.0.9_eabi/usr/include/mysql -o /tmp/mysql_test /tmp/mysql_test.c -L/opt/openwrt-git-trunk/staging_dir/target-arm_mpcore_uClibc-1.0.9_eabi/usr/lib/mysql -lmysqlclient
In file included from /tmp/mysql_test.c:1:0:
/opt/openwrt-git-trunk/staging_dir/target-arm_mpcore_uClibc-1.0.9_eabi/usr/include/mysql/my_global.h:897:0: warning: "isnan" redefined [enabled by default]
 #define isnan(x) ((x) != (x))
 ^
In file included from /opt/openwrt-git-trunk/staging_dir/target-arm_mpcore_uClibc-1.0.9_eabi/usr/include/mysql/my_global.h:426:0,
                 from /tmp/mysql_test.c:1:
/opt/openwrt-git-trunk/staging_dir/toolchain-arm_mpcore_gcc-4.8-linaro_uClibc-1.0.9_eabi/include/math.h:281:0: note: this is the location of the previous definition
 #  define isnan(x) \
 ^
[debian@debian:/opt/openwrt-git-trunk.2 480%] ~ dir /tmp/mysql_test*
-rwxr-xr-x 1 debian users 6928 May  2 07:27 /tmp/mysql_test
-rw-r--r-- 1 debian users  156 May  2 07:26 /tmp/mysql_test.c
[debian@debian:/opt/openwrt-git-trunk.2 481%] ~ file /tmp/mysql_test
/tmp/mysql_test: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

The discussion might have continued from here.