Use cygwin and ndk to compile libevent for Android

Source: Internet
Author: User

Last time, I was very excited because I had compiled the libevent static library on Ubuntu, but the tragedy was that I couldn't live or die when I got it on Windows and used cygwin as a link, it is reported that event_init is not implemented in a bunch of other methods, but the static library is clearly under the OBJ/local/armeabi directory, and the corresponding everywhere function can be found when the static library is opened, why can't I find it? I haven't figured it out yet, but the version compiled with cygwin later seems a little different from the static library, because I haven't figured out the compiling of ndk yet, on Ubuntu, I specified platforms and the corresponding compiler. I don't know if it is caused by mismatch. Otherwise, there is no need to have so many GCC and LD versions in the ndk directory. It is confusing to compile programs on non-Windows platforms. However, at least later I found a way to use cygwin in win7 to compile the android libevent that cocos2dx can use.

Before compilation, I want to make the compilation methods and methods as detailed as possible. At least I have not found any relevant articles, and of course it may be too simple, but I am so confused. Compiling environment
Operating System Win7 64bit
Auxiliary compilation environment Cygwin 1.7.14
Compiler Ndk r8e
Libevent version 2.0.21-stable (for Android)

You must prepare these items (including download, installation, and corresponding path export), search for them online, and download the libevent version, do not download the official version.
Libevent for Android source code preparation

Here the Special is to use git corresponding to the dedicated for Android version of libevent, here are: https://github.com/ventureresearch/libevent/archive/patches-2.0.zip

Note that if it is on cygwin, compilation may be problematic. It seems that ndk is executed in cygwin, and soft connections in Linux are not supported, all header files in the OpenSSL directory under the inlcude directory in OpenSSL are soft connections. Therefore, if you want to support OpenSSL, I have nothing to do here (maybe it may not be feasible in Linux ). After the corresponding libevent compressed package is unbundled, it is placed in the cocos2dx directory. Here, the project is created through the Python script in tools, so all projects will be under the cocos2dx project directory. Then edit android. MK file, delete all the source files and directory paths that support OpenSSL (do not simply use # annotations, because the backslashes will be commented together, in this way, most of the remaining source files are commented out, so that the compiled static library will have fewer functions ). The document content is listed here:
##################################### Build libevent as separate libraryLOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_ARM_MODE:= armLOCAL_MODULE:= event_staticLOCAL_MODULE_TAGS:= optional#    bufferevent_openssl.c LOCAL_SRC_FILES := \    buffer.c \    bufferevent.c \    bufferevent_filter.c \    bufferevent_pair.c \    bufferevent_ratelim.c \    bufferevent_sock.c \    epoll.c \    epoll_sub.c \    evdns.c \    event.c \    event_tagging.c \    evmap.c \    evrpc.c \    evthread.c \    evthread_pthread.c \    evutil.c \    evutil_rand.c \    http.c \    listener.c \    log.c \    poll.c \    select.c \    signal.c \    strlcpy.c#    external/openssl/includeLOCAL_C_INCLUDES := \    $(LOCAL_PATH) \    $(LOCAL_PATH)/android \    $(LOCAL_PATH)/includeLOCAL_CFLAGS := -DHAVE_CONFIG_H -DANDROID -fvisibility=hiddeninclude $(BUILD_STATIC_LIBRARY)#include $(BUILD_SHARED_LIBRARY)

Okay, here we will show ndk how to compile libevent and generate the corresponding static library name libevent_static.a. After compiling to your project and above, you can open your project Android. mk and add the following statement:

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \...    $(LOCAL_PATH)/../../../../libevent \    $(LOCAL_PATH)/../../../../libevent/include \    $(LOCAL_PATH)/../../../../libevent/android...LOCAL_WHOLE_STATIC_LIBRARIES += event_static...$(call import-module,libevent)

Do not copy the middle. To explain it a bit:

  1. Because libevent is used, it is necessary to tell the compiler where the header file of the libevent is located, such as the local_c_effecdes settings, the following three directories are added: libevent, libevent/include, and libevent/Android. My libevent directory is directly under the cocos2dx Directory, which is at the same level as the project directory.
  2. Local_whole_static_libraries tells the compiler to link the static library, that is, libevent_staitc.a.
  3. The final statement indicates that the ndk needs to compile an external module and find Android. mk in the ibevent directory.
Now you can compile the libevent_staitc.a static library. It can be used for testing on Android.
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.