關(guān)于Android mk 一些規(guī)則介紹可以參考這篇文章
Android.mk編譯目標(biāo)常見的一些編譯目標(biāo) http://www.reibang.com/p/1ad479ccf052
本文是記錄實(shí)際編譯過程中頭文件的include一個(gè)問題
先看一個(gè)簡單的mk 文件
LOCAL_PATH:= ${call my-dir}
include $(CLEAR_VARS)
LOCAL_MODULE := libhelloword.so
LOCAL_C_INCLUDE += hellowrod.h
LOCAL_SRC_FIELS := hellowrod.cpp
LOCAL_MODULE_TAGS := optional
include $(BUILD_ SHARED_LIBRAYIES)
我在實(shí)際的Android.mk 文件中 添加了他人模塊頭文件路徑的引用
LOCAL_C_INCLUDE += xxx/xxx/xxx
然后在代碼debug.cpp中添加
#include “common.h”
ALOGD(“%d”, COMMON_MODE); // COMMON_MODE define @ common.h
但是編譯一直報(bào)錯(cuò)誤 COMMON_MODE not defined
原因是根本就沒有編譯到 xxx/xxx/xxx/common.h 里面的內(nèi)容
為什么會(huì)沒有編譯到溯捆,猜測(cè)是有另外一個(gè)頭文件 common.h被引用了祟滴,這里引申出一個(gè)問題赘艳,怎么看c/c++編譯過程中使用了哪些依賴的頭文件?
C:
This will give make dependencies which list absolute paths of include files:
gcc -M hello.c
If you don't want the system includes (i.e. #include <something.h>) then use:
gcc -MM hello.c
CPP:
g++ -H hello.c
我這邊是CPP涝开,所以我在Android.mk中增加一個(gè)選項(xiàng)
LOCAL_CFLAGS += -H
然后source & lunch & mm -B
通過編譯log可以看到確實(shí)是引用了錯(cuò)誤的 common.h
知道原因了就有挺多改法的,不過coding的時(shí)候還是要注意盡量不要使用 common.h 這類常見或者通用的名字痊项,畢竟很容易出現(xiàn)依賴錯(cuò)誤的問題
Android編譯系統(tǒng)中頭文件搜索路徑的順序問題可以看這篇文章 Android編譯系統(tǒng)中頭文件搜索路徑的順序問題