Android NDK use third-party libraries

NDK r5 began to support pre-compiled shared library. Pre-compiled shared library is to get the source code to compile shared libraries from elsewhere, rather than the Android system comes. As follows:
1. Statement shared library module
to declare a separate shared library modules. If Android.mk libfoo.so and located in the same directory. The Android.mk should read:
    LOCAL_PATH: = $ (Call My-dir)

    $ the include (CLEAR_VARS)
    LOCAL_MODULE: foo = #-the prebuilt module name
    LOCAL_SRC_FILES: = libfoo.so # module file path (relative LOCAL_PATH)

    include $ (PREBUILT_SHARED_LIBRARY) # Note that this is not BUILD_SHARED_LIBRARY
the shared object will be copied to $ PROJECT / obj / local and $ PROJECT / libs / <abi> (strip off)

2, reference the shared libraries in other modules
    in Android.mk, the name of the shared library module added LOCAL_STATIC_LIBRARIES (static library) or LOCAL_SHARED_LIBRARIES (DLL)
for example, using libfoo.so method:
    the include $ (CLEAR_VARS)
    LOCAL_MODULE : = foo-the User
    LOCAL_SRC_FILES: = foo-user.c
    LOCAL_SHARED_LIBRARY: = foo-prebuilt
    the include $ (BUILD_SHARED_LIBRARY)
3, as a shared library header files exported
    this shared library generally have the appropriate header files, such as libfoo.so there foo. h.

A simple way (written in Android.mk):    

   $ the include (CLEAR_VARS)
   LOCAL_MODULE: foo = the prebuilt-
   LOCAL_SRC_FILES: = for libfoo.so
   LOCAL_EXPORT_C_INCLUDES: = $ (LOCAL_PATH) / the include
   the include $ (PREBUILT_SHARED_LIBRARY)
    Thus, using the shared library module will be in its variable added to the header LOCAL_C_INCLUDES search path.
4, debugging Shared Libraries
    suggest you retain the shared library debugging information. $ PROJECT / libs / (no debugging information) after <abi> shared library directory are strip. There are debugging version can be used ndk-gdb.

5, the shared library ABI
    your target system compatibility shared library ABI is very important.
    Check TARGET_ARCH_ABI, have the following values:
        armeabi => ARMv5TE above
        armeabi-v7a => ARMv7 more
        x86 => x86
    recommended: armeabi ABI can run on all ARM CPU.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

First introduced to the LOCAL_CFLAGS

LOCAL_CFLAGS + = -DXXX equivalent to adding a macro definition #define XXX in all source files

1、-Wall

It is open warning switch

2, -O

Represents the default optimization, optional: -O0 not optimized, -O1 low-level optimization, -O2 mid-level optimization, -O3 advanced optimization, -Os code space optimization

3、-g

Debug information is generated, the generated executable file having the debugging information and source code associated

4、-fopenmp

OpenMp proposed by the lead OpenMP Architecture Review Board, and has been widely accepted, a guidance program compile processing multiprocessor shared memory parallel program to the system design (Compiler Directive). OpenMP support for programming languages including C language, C ++ and Fortran; and support OpenMp compilers include Sun Compiler, GNU Compiler and Intel Compiler and so on. OpenMp provides a high-level abstraction of parallel algorithms described, by adding special pragma programmer in the source code to indicate their intention, whereby the compiler can automatically parallelized program, synchronization and mutual exclusion added where necessary and communications. When you choose to ignore these pragma, or the compiler does not support OpenMp, but also the program degenerated into the usual procedure (usually serial), the code can still operate normally, but can not use multi-threading to speed up program execution.
5, -D

Increase global macro definition
6, -ffast-math  

Floating-point optimization options -ffast-math: dramatically increase the speed of floating point operations

7, -mfloat-abi = softfp floating point

8, exceptions standard library exceptions 

9、LOCAL_LDFLAGS =-fuse-ld=bfd

gcc compiler flag CFLAGS Parameter Description

CFLAGS = -g -O2  -Wall -Werror -Wno-unused


The corresponding language
-S
just does not compile compilation, assembly code generated
-E
were only pre-compiled, no other processing
-g
include standard debugging information in the executable
-o file
output to a file in the output file
-v
print out internal compiler compiler version command line information for each process and compiler
-I dir
Add dir directory in the search path list header file
-L dir
Add dir directory in the search path list of library files
-static
link static library
-llibrary
link library file called library

--------------------- 
Source: CSDN 
Original: https: //blog.csdn.net/smfwuxiao/article/details/6591927 

Guess you like

Origin blog.csdn.net/u014421422/article/details/91450302