COCOS2DX compiling C + + libraries from the NDK

Source: Internet
Author: User
Tags lua

The NDK compiles C + + libraries and then implements critical code encapsulation through JNI calls, which is the most commonly used technology in Android applications, where important code implementations can be hidden, protected from leaks, and faster to pack.

There are a number of practical examples in the NDK sample folder, where Hello-jni has an example of compiling C + +.

First, create a JN folder, place android.mk and application.mk two files in the folder, Android.mk file is mainly

Write compiled C + + code, packaged library names, packaged library types (static library or dynamic library), referenced modules, and so on. Application.mk

is primarily the type of instruction that the packaged library belongs to, the NDK version used, the GNU version, references to other libraries, and so on.

To copy the C + + code that will be compiled to the JNI folder, here is an example of the android.mk and application.mk two files.

APPLICATION.MK:

#只导出arm版本的库

App_abi: = Armeabi

# using ndk4.8 's library version
Ndk_toolchain_version: = 4.8

# using STL's library type
App_stl: = gnustl_static
App_cppflags: =-frtti-dcc_enable_chipmunk_integration=1-dcocos2d_debug=1-std=c++11-fsigned-char

ANDROID.MK:

Local_path: = $ (call My-dir)

Include $ (clear_vars)
Local_cpp_features + = Exceptions

#这里是导出模块的名字
Local_module: = Mirage

#这里是导出模块的文件名
Local_module_filename: = Libmirage

#要编译jni目录下的代码文件夹
Local_c_includes: = $ (Local_path)/lua\
$ (Local_path)/include


#traverse all the directory and subdirectory
Define Walk
$ (wildcard $ (1)) $ (foreach E, $ (wildcard $ (1)/*), $ (call Walk, $ (e)))
Endef

#traverse Classes Directory

# filter files, compile only C + + and C files
All_files: = $ (call walk, $ (local_path)/SRC)

Cpp_file_list: = $ (Filter%.cpp, $ (all_files))
Cpp_file_list + = $ (filter%.c, $ (all_files))
Cpp_file_list + = $ (filter%.cc, $ (all_files))


Local_src_files: = $ (cpp_file_list:$ (Local_path)/%=%)
Local_export_c_includes: = $ (Local_path)/. /include

Local_cflags + =-wno-psabi
Local_export_cflags + =-wno-psabi

Local_whole_static_libraries: = cocos_lua_static

# indicates that the exported library is a. So Static library
Include $ (build_static_library)

#这里是导入要引用的外部c代码的路径

$ (call Import-add-path,/users/hemjohn/desktop/onepiece_client/frameworks/cocos2d-x)

#这里是导入要引用的外部库模块

$ (call import-module,scripting/lua-bindings/proj.android)

With the above steps,

Directories in the console, CD-to-JNI folder

Execute the ndk-build executable file (Windows System execution Ndk-build.cmd) inside the Ndk folder, or in the environment variable, add

The NDK directory.

The following are the results of the execution:

In the same directory as JNI, an obj folder is generated, which contains the compiled. A library

Reprint please indicate the source, from the blog Park Hemjohn

COCOS2DX compiling C + + libraries from the NDK

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.