Cross-compile Android libevent library on Ubuntu

Source: Internet
Author: User

Here, I will record the problems I encountered when developing cocos2dx for Android. Maybe many people are as confused as I am, but I can record a little bit, I hope to make it into a series to help everyone. Of course, I still helped myself at the beginning, and my memory is poor. To be honest, compilation is really a lot of pitfalls.

During this time, I was troubled by finding a cross-platform socket communication library on cocos2dx (to be honest, I have been writing about the server on windows, and I am not familiar with anything, so now it's a little too difficult. There is always a hard time to do everything. Now, to tell the truth, I am very happy and others envy me. I can concentrate on this field, too, my boss ), the following methods are available:

  1. Write one by yourself using the BSD specification, such as odsocket (Thank you for providing this)
  2. Find a common library implementation

In fact, I tried it all. The first one is still an alternative solution. I mainly want to find a useful general library to do this, so I found libevent after finding it, I searched the internet and it seems that there are also examples of successful compilation and use on iOS, windows, and Android. IOS is better. Someone directly shares several static library files compiled on Android. Of course, if I compile it, it will be shared with you.

Preparations for downloading libevent source code

First go to git next dedicated for Android libevent (should just write an android. mk),: https://github.com/ventureresearch/libevent and then release to local.

To release the package, you can run the unzip command to release it because the downloaded file is in the ZIP format. If not, use sudo apt-Get install unzip to install it (the premise is to connect to the Internet)

Running Environment

I use Ubuntu as an example. I installed a virtual machine on Ubuntu and used the 64-bit server version 12.04.2 lts. If you share files, you can directly install a winscp, if SSH cannot be used, install OpenSSH on Ubuntu, for example, sudo apt-Get install OpenSSH by pressing yes to the end. I won't go into details about how to use winscp. I can simply go to Google or Baidu, or simply open it and use it.

Compilation preparation

In the released file, run. /autogen. sh. The configure file may need automake and libtool. If not, use the old method of sudo apt-Get install XXX to install it on your own.

After autogen. Sh runs, many configure-related files and install. Sh files should be added to the directory.

Export environment variables directly in the command line
export NDK_ROOT=work/Android/android-ndk-r8e
export PATH=$PATH:$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin

Of course, you must download the ndk first. Download the corresponding version based on your machine and operating system. My machine uses the r8e linux64-bit version. The path is added later to find the arm-Linux-androideabi-GCC compiler.


Writing the configure. Sh file is dispensable, but it is difficult for me to write it here. If I re-enter the command every time, I am too tired to write a script and run it every time. The content is as follows:
 #! /bin/sh ./configure \ --host=arm-linux-androideabi \ CC=arm-linux-androideabi-gcc \ LD=arm-linux-androideabi-ld \ CPPFLAGS="-I$NDK_ROOT/platforms/android-14/arch-arm/usr/include/" \ CFLAGS="-nostdlib" \ LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-14/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-14/arch-arm/usr/lib/" \ LIBS="-lc -lgcc -L$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.7"

Here, we configure the platform for Android-14 according to the Environment configuration on our machine, and the corresponding compilation tool is 4.7.

Note that, because arm itself does not support floating-point operations, it must be implemented through a soft floating-point library, which is libgcc. a, so we need to connect-lgcc here, and the corresponding library is provided in toolchains. The following directory specifies libgcc. a. In the test example after make, the corresponding division is used, and xxxmod and so on may be reported.

Run the script in the directory and enter it directly. /configure. sh. In this case, there should be other issues. If yes, follow the prompts (usually in the current folder config. logs recorded in the log file. I reported that the C compilation library could not be found, and then the arm-Linux-androideabi-GCC could not be found. In the end, when the export was found, the directory was wrong, with 64 missing, sweat, please do not copy it. After creating a soft connection to two library files, I read the article on Stack Overflow. It seems that the ndk toolchain does not find the library files in the specified lib directory, so the crtbegin_so.o and crtend_so.o cannot be found. The solution is to establish a soft connection to the corresponding file in the current directory, as shown below:
ln -s $NDK_ROOT/platforms/android-14/arch-arm/usr/lib/crtbegin_so.oln -s $NDK_ROOT/platforms/android-14/arch-arm/usr/lib/crtend_so.o

In this way, the current libevent directory will have a soft connection to the two files, so that the files will not be found when making. Of course, here I am equivalent to putting all the problems above. Of course, you can also make them before solving this problem. After all, I am executing make on this detour through configure. sh, The MAKEFILE file will be generated. You can open it and check it, but the amount is large. I did not take it carefully. After a successful process, the corresponding library files are generated in. LibsDirectory, or a hidden file..Copy the file. The corresponding library files are also provided in my attachment. References

  1. This article is the first reference http://blog.csdn.net/optman/article/details/8651458 I think libevent is feasible
  2. This article gave me up cgywin to compile the http://blog.csdn.net/optman/article/details/8651458 on Ubuntu
  3. This stack overflow is basically my reference http://stackoverflow.com/questions/11655911/cross-compiling-libevent-for-android for cross-compiling.
  4. Make error, corresponding crtbegin_so.o and crtend_so.o cannot find the solution http://stackoverflow.com/questions/6881164/crtbegin-so-o-missing-for-android-toolchain-custom-build
  5. The blog of the grassroots teacher, the article http://blog.chinaunix.net/uid-26833883-id-3282967.html about the floating point operation Error
  6. This article is about how to use ndk to compile open source library, the length is too large, I did not look at it carefully, but should be very helpful http://warpedtimes.wordpress.com/2010/02/03/building-open-source-libraries-with-android-ndk/
Download the libevent library, which contains four libevent. A, libevent_core.a, libevent_extra.a, and libevent_pthreads.a.
Related Article

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.