Libmysqlclient cross-compilation based on x86 architecture OpenWrt

Source: Internet
Author: User

1. Build a cross-compilation environment
First, build a cross-compilation environment on your own machine. I'm using the Ubuntu14.04 x86_64,gcc-4.8.3. If you want to set up a very complete cross-compilation environment, you need to install OPENWRT buildroot environment, operation steps:
Http://wiki.openwrt.org/doc/howto/buildroot.exigence,

Note that after make Menuconfig the configuration interface, the main selection of the target system architecture, such as my x86, other such as ar71xx, and so on, another check compiled toolchain, there is a package openwrt SDK (many of the documents mentioned, We may as well tick the bar).
From the Make Menuconfig interface, this should be a compilation of the entire OpenWrt, and thus, like compiling other systems, the process looks long and boring. We might as well change the idea, we generally cross-compile using the source package in the Configure script to specify the--host option represents the target platform to be compiled, such as my i486-openwrt-linux, and according to experience, configure is based on this value, After that, add the compiler that-gcc/-g++ form the target platform for the i486-openwrt-linux-gcc/g++ to make the call compilation, and then find it under the directory specified by the environment variable path according to the resulting compiler name.
Based on this empirical principle, why should we wait for such a long time to be on the road of compiling? OK, let's go to the source of OpenWrt x86 directly download the official compiled compiler, and then set the path path is not good enough. Well, in

You can see toolchain, download, unzip, set the environment variable path, environment variables are generally $toolchain_home/bin, this $toolchain_home represents your tool chain home directory.
You can test the command line input i486-openwrt-linux-and then press the TAB key will not fill out a lot of things, if you can, that means the path is set. Through this method, I compiled through the libnet, Libpcap, Libnids, this according to my previous record of the document, the compilation process is really silky smooth ... However, this cross-compiler tool chain will burst warning, said there is no $staging_dir this environment variable, in fact, ignore this no problem, if you do not need the target platform of other libraries, if really uncomfortable, you can set a bit, if you set the path of the time is $ Toolchain_home/bin words, this $staging_dir is $toolchain_home.
If BuildRoot is installed, it is also necessary to set the two environment variables, the same as above. Later when compiling another thing to link Pthread Library, this time must use this full buildroot, the compiler will staging_dir the specified path as the default directory of header files and libraries, should be used in the SDK Pthread library.
2. Cross-compiling Libmysqlclient
This process can be referred to
http://blog.csdn.net/lilongherolilong/article/details/7521736

This article, to strictly abide by the mysql-connector version, and refer to the following 5 floor comments. CMake build makefile, make compiles, error occurs
My_global.h:1582:22:error:static declaration of ' rint ' follows non-static declaration

This is certainly the same as the reference article compiler version inconsistency caused, hateful original article about the environment without emphasis, my cmake version is 2.8.12.2, cross compiler is also based on gcc-4.8.3. Fortunately, Google found that someone said comment it out, OK, let's comment it out. Next re-make, see Fast, 95% stop, see its error, a look undefined reference, of course, is the link error, and then look at the Floor,pow,log and other functions of undefined reference, the problem is obvious, not linked to the math library, The link option is certainly less-lm. So what is the compiler command, from the current make display information can only see progress, and the target file, error message, we need is similar to gcc-o test test.c such things, and then add-lm behind. Well, if you're familiar with make, then things are going to be easy, right, make verbose=1, show me the details, well, we found the last command that went wrong:
/home/weizheng/openwrt/staging_dir/toolchain-i386_i486_gcc-4.8-linaro_uclibc-0.9.33.2/bin/ I486-OPENWRT-LINUX-GCC    -wall-fno-rtti-fno-exceptions-o3-dndebug-ddbug_off    Cmakefiles/mysql_client_ TEST.DIR/MYSQL_CLIENT_TEST.C.O cmakefiles/mysql_client_test.dir/__/mysys/my_memmem.c.o  -o mysql_client_test- Rdynamic. /libmysql/libmysqlclient.a-lpthread

Oh, it turns out there's no-lm behind this compiled command. OK, we analyze this command and discover that the source file is
CMAKEFILES/MYSQL_CLIENT_TEST.DIR/MYSQL_CLIENT_TEST.C.O CMAKEFILES/MYSQL_CLIENT_TEST.DIR/__/MYSYS/MY_MEMMEM.C.O

But does not seem to be in the source code directly under the directory, because in the source directory to re-execute the command, will say that the above two files are not, how to do it, this file exactly where to go, OK, if you are familiar with the Find command, then this problem is solved.
[Email protected]:~/semanalysis/x86_openwrt_lib/mysql-connector-c-6.0.2$ Find. -name MYSQL_CLIENT_TEST.C.O./TESTS/CMAKEFILES/MYSQL_CLIENT_TEST.DIR/MYSQL_CLIENT_TEST.C.O

Well, finally found the goods, in the test directory, CD in, execute the compile command, OK, this even past. Return to the upper directory, continue make, and find another error, repeating the process. Of course there seems to be a lot of compiler commands are not-LM, we have to add, this is really annoying. Well, once again come up with our killer, if you ... Make,makefile enough to be familiar with the words, in general, make in accordance with the Makefile organization grammar interpretation of the implementation of makefile, OK, then generally, there will be an option called ldflags, well, that's it, We directly modify this ldflags plus-lm is not finished, but in the makefile to find Ldflags is not a sensible choice, so much makefile, you know who put in which inside, fortunately, there is this method, is the environment variable.
Export LDFLAGS+=-LM

Then re-cmake,make is OK,finally a gorgeous success, hehe hehe ...
Oh yes, don't forget make install!
================= main =================Wei Zheng Weiz

Libmysqlclient cross-compilation based on x86 architecture OpenWrt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.