ãã1. æ¦è¿°
ããé¦å å顾ä¸ä¸ Android NDK å¼åä¸ï¼Android.mk å Application.mk åèªçèè´£ã
ããAndroid.mkï¼è´è´£é ç½®å¦ä¸å 容ï¼
ããï¼1ï¼ æ¨¡ååï¼LOCAL_MODULEï¼
ããï¼2ï¼ éè¦ç¼è¯çæºæ件ï¼LOCAL_SRC_FILESï¼
ããï¼3ï¼ ä¾èµç第ä¸æ¹åºï¼LOCAL_STATIC_LIBRARIESï¼LOCAL_SHARED_LIBRARIESï¼
ããï¼4ï¼ ç¼è¯/é¾æ¥é项ï¼LOCAL_LDLIBSãLOCAL_CFLAGSï¼
ããApplication.mkï¼è´è´£é ç½®å¦ä¸å 容ï¼
ããï¼1ï¼ ç®æ å¹³å°çABIç±»åï¼é»è®¤å¼ï¼armeabiï¼ï¼APP_ABIï¼
ããï¼2ï¼ Toolchainsï¼é»è®¤å¼ï¼GCC 4.8ï¼
ããï¼3ï¼ C++æ ååºç±»åï¼é»è®¤å¼ï¼systemï¼ï¼APP_STLï¼
ããï¼4ï¼ release/debug模å¼ï¼é»è®¤å¼ï¼releaseï¼
ããç±æ¤æ们å¯ä»¥çå°ï¼æ¬æææ¶åçç¼è¯é项å¨Android.mkåApplication.mkä¸åæåºç°ï¼ä¸é¢æ们å°ä¸ä¸ªä¸ªè¯¦ç»ä»ç»ã
ãã2. APP_ABI
ããABIå ¨ç§°æ¯ï¼Application binary interfaceï¼å³ï¼åºç¨ç¨åºäºè¿å¶æ¥å£ï¼å®å®ä¹äºä¸å¥è§åï¼å 许ç¼è¯å¥½çäºè¿å¶ç®æ 代ç å¨ææå ¼å®¹è¯¥ABIçæä½ç³»ç»å硬件平å°ä¸æ éæ¹å¨å°±è½è¿è¡ãï¼å ·ä½çå®ä¹è¯·åè ç¾åº¦ç¾ç§ æè ç»´åºç¾ç§ ï¼
ããç±ä¸è¿°å®ä¹å¯ä»¥å¤æï¼ABIå®ä¹äºè§åï¼èå ·ä½çå®ç°åæ¯ç±ç¼è¯å¨ãCPUãæä½ç³»ç»å ±åæ¥å®æçãä¸åçCPUè¯çï¼å¦ï¼ARMãIntel x86ãMIPSï¼æ¯æä¸åçABIæ¶æï¼å¸¸è§çABIç±»åå æ¬ï¼armeabiï¼armeabi-v7aï¼x86ï¼x86_64ï¼mipsï¼mips64ï¼arm64-v8açã
ããè¿å°±æ¯ä¸ºä»ä¹æ们ç¼è¯åºæ¥çå¯ä»¥è¿è¡äºWindowsçäºè¿å¶ç¨åºä¸è½è¿è¡äºMac OS/Linux/Androidå¹³å°äºï¼å 为CPUè¯çåæä½ç³»ç»åä¸ç¸åï¼æ¯æçABIç±»åä¹ä¸ä¸æ ·ï¼å æ¤æ æ³è¯å«å¯¹æ¹çäºè¿å¶ç¨åºã
ããèæ们æ说çâ交åç¼è¯âçæ ¸å¿åçä¹è·è¿äºå¯åç¸å ³ï¼äº¤åç¼è¯ï¼å°±æ¯ä½¿ç¨äº¤åç¼è¯å·¥å ·ï¼å¨ä¸ä¸ªå¹³å°ä¸ç¼è¯çæå¦ä¸ä¸ªå¹³å°ä¸çäºè¿å¶å¯æ§è¡ç¨åºï¼ä¸ºä»ä¹å¯ä»¥åå°ï¼å 为交åç¼è¯å·¥å ·å®ç°äºå¦ä¸ä¸ªå¹³å°æå®ä¹çABIè§åãæ们å¨Windows/Linuxå¹³å°ä½¿ç¨Android NDK交åç¼è¯å·¥å ·æ¥ç¼è¯åºAndroidå¹³å°çåºä¹æ¯è¿ä¸ªéçã
ããè¿éç»åºææ° Android NDK ææ¯æçABIç±»åååºå«ï¼
ããé£ä¹ï¼å¦ä½æå®ABIç±»åå¢ï¼å¨ Application.mk æ件ä¸æ·»å ä¸è¡å³å¯ï¼
ããAPP_ABI := armeabi-v7a //åªç¼è¯armeabi-v7açæ¬
APP_ABI := armeabi armeabi-v7a //åæ¶ç¼è¯armeabiï¼armeabi-v7açæ¬
APP_ABI := all //ç¼è¯ææçæ¬
ãã3. LOCAL_LDLIBS
ããAndroid NDK é¤äºæä¾äºBionic libcåºï¼è¿æä¾äºä¸äºå ¶ä»çåºï¼å¯ä»¥å¨ Android.mk æ件ä¸éè¿å¦ä¸æ¹å¼æ·»å ä¾èµï¼
ããLOCAL_LDLIBS := -lfoo
ããå ¶ä¸ï¼å¦ä¸å 个åºå¨ Android NDK ç¼è¯æ¶å°±é»è®¤é¾æ¥äºï¼ä¸éè¦é¢å¤æ·»å å¨ LOCAL_LDLIBS ä¸ï¼
ããï¼1ï¼ Bionic libcåº
ããï¼2ï¼ pthreadåºï¼-lpthreadï¼
ããï¼3ï¼ mathï¼-lmathï¼
ããï¼4ï¼ C++ support library (-lstdc++)
ããä¸é¢æåäºä¸ä¸ªè¡¨ï¼ç»åºäºå¯ä»¥æ·»å å°âLOCAL_LDLIBSâä¸çä¸åçæ¬çAndroid NDKææ¯æçåºï¼
ããä¸é¢æ¯ææ»ç»çä¸äºå¸¸ç¨çCFLAGSç¼è¯é项ï¼
ããï¼1ï¼éç¨çç¼è¯é项
ãã-O2 ç¼è¯ä¼åé项ï¼ä¸è¬éæ©O2ï¼å ¼é¡¾äºä¼åç¨åº¦ä¸ç®æ 大å°
ãã-Wall æå¼ææç¼è¯è¿ç¨ä¸çWarning
ãã-fPIC ç¼è¯ä½ç½®æ å ³ç代ç ï¼ä¸è¬ç¨äºç¼è¯å¨æåº
ãã-shared ç¼è¯å¨æåº
ãã-fopenmp æå¼å¤æ ¸å¹¶è¡è®¡ç®ï¼
ãã-Idir é 置头æ件æ索路å¾ï¼å¦ææå¤ä¸ª-Ié项ï¼åè·¯å¾çæç´¢å å顺åºæ¯ä»å·¦å°å³çï¼å³å¨åé¢çè·¯å¾ä¼è¢«éæç´¢
ãã-nostdinc 该é项æ示ä¸è¦æ åè·¯å¾ä¸çæ索头æ件ï¼èåªæç´¢-Ié项æå®çè·¯å¾åå½åè·¯å¾ã
ãã--sysroot=dir ç¨dirä½ä¸ºå¤´æ件ååºæ件çé»è¾æ ¹ç®å½ï¼ä¾å¦ï¼æ£å¸¸æ åµä¸ï¼å¦æç¼è¯å¨å¨/usr/includeæ索头æ件ï¼å¨/usr/libä¸æç´¢åºæ件ï¼å®å°ç¨dir/usr/includeådir/usr/libæ¿ä»£åæ¥çç¸åºè·¯å¾ã
ãã-llibrary æ¥æ¾å为libraryçåºè¿è¡é¾æ¥
ãã-Ldir å¢å -lé项æå®çåºæ件çæ索路å¾ï¼å³ç¼è¯å¨ä¼å°dirè·¯å¾ä¸æç´¢-læå®çåºæ件ã
ãã-nostdlib 该é项æ示é¾æ¥çæ¶åä¸è¦ä½¿ç¨æ åè·¯å¾ä¸çåºæ件
ããï¼2ï¼ ARMå¹³å°ç¸å ³çç¼è¯é项
ãã-marm -mthumb äºéä¸ï¼æå®ç¼è¯thumbæ令éè¿æ¯armæ令é
ãã-march=name æå®ç¹å®çARMæ¶æï¼å¸¸ç¨çå æ¬ï¼-march=armv6ï¼ -march=armv7-a
ãã-mfpu=name ç»åºç®æ å¹³å°çæµ®ç¹è¿ç®å¤çå¨ç±»åï¼å¸¸ç¨çå æ¬ï¼-mfpu=neonï¼-mfpu=vfpv3-d16
ãã-mfloat-abi=name ç»åºç®æ å¹³å°çæµ®ç¹é¢ç®ABIï¼æ¯æçåæ°å æ¬ï¼âsoftâ, âsoftfpâ and âhardâ