# 目標檔名
target := libmymath.so
# 生成的目標所放置的位置
target_path :=../
# 編譯引數
cc := g++
# 依賴庫名稱,如:libs=-lpthread
libs :=
# 指定依賴庫位置,多個引用庫之間以空格分開, 如: ldflags=-l/usr/lib -l/***/lib
ldflags :=
# 向**提供巨集定義, 一般**這樣使用:
# #ifdef ***x
# ...
# #endif
# 巨集定義有2種方式: (1) -d define1 (2) -d define2=1000
# 多個巨集定義以空格分開, 如: defines=-dgt60 -disandroid=1
defines :=
# 依賴標頭檔案路徑(當前路徑: i.), 多個路徑以空格分開, 如: includes=-i/usr/include -i/path/include
includes := -i.
# -o0:表示編譯時沒有優化
# -o1:表示編譯時使用預設優化
# -o2:表示編譯時使用二級優化
# -o3:表示編譯時使用最高端優化
# -os: 優化**大小,其使能了-o2的所有選項,相當於-o2.5
cflags := -g -wall -o3 -std=c++11 $(defines) $(includes)
cxxflags:= $(cflags)
# vpath告訴編譯器當前目錄和指定目錄都按照當前規則編譯
vpath = . ./subdir
# 自動查詢所有.c和.cpp檔案,並將目標定義為同名.o檔案
# wildcard得到當前目錄(./)和其子目錄下的所有字尾為.cpp檔案
# 如果還有目錄則再增加乙個wildcard, 比如當前目錄下還有乙個子目錄***,如: source := $(wildcard *.cpp) $(wildcard ***/*.cpp)
source := $(wildcard *.cpp) $(wildcard subdir/*.cpp)
# notdir去除路徑得到檔名
src_withoutdir:= $(notdir $(source))
# patsubst把.c及.cpp替換成同名.o, 如果手動寫.o則不需要source, 如: objs = mymath.o testlib.o
objs := $(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(src_withoutdir)))
# 顯示source, src_withoutdir, objs的值
#out:
# @echo $(source)
# @echo $(src_withoutdir)
# @echo $(objs)
# -shared: 編譯成動態庫
$(target) : $(objs)
$(cc) -shared -o $@ $(objs) $(ldflags) $(includes)
ifeq ($(target_path),)
# 如果未設定目標路徑則不拷貝(目標所在路徑為當前目錄)
else
# 把.so檔案拷貝到指定目錄種
cp $(target) $(target_path)
endif
%.o : %.cpp
# -fpic: 告訴編譯器產生與位置無關**(position-independent code)
$(cc) $(cxxflags) -fpic -c $< -o $@ $(ldflags) $(libs)
.phony : clean
clean:
rm -f *.o
rm -f $(target)
Linux下NDK編譯so庫
2 隨便在哪個目錄直接解壓 3 配置系統環境變數 vim etc profile 在檔案末尾新增如下內容 export android ndk ndk路徑 export path and roid ndk android ndk androi dn d k 1 建立jni目錄 mkdir jni 2...
Linux編譯 a模板
目標檔名 target libmymath.a 生成的目標所放置的位置 target path 編譯引數 cc g 建立靜態庫使用ar命令 ar ar ranlib對靜態庫符號索引表進行更新 ranlib ranlib 依賴庫名稱,如 libs lpthread libs 指定依賴庫位置,多個引用庫...
ndk 編譯 so檔案
使用ndk build編譯,如果windows需要cygwin環境,cygwin android ndk linux就好辦了 直接在專案路徑使用 ngk build指令碼就能編譯了 引用 一 準備工作 cygwin android ndk 二 安裝cygwin可以搜尋一下比較簡單。安裝時注意選擇包時...