之前在tensorflow-master上用bazel編這好好的程式,挪到android原始碼裡就沙比了。。。沒辦法只能用makefile整體編譯。。。然而作為菜鳥並不會寫makefile。這裡大概寫一下涉及到的規則和注意事項。
首先,目標是吧build檔案的內容和功能遷移出來。
cc_library(
name = "bitmap_helpers",
srcs = [
"bitmap_helpers.cc",
],hdrs = [
"bitmap_helpers.h",
"bitmap_helpers_impl.h",
"label_image.h",
],deps = [
"//tensorflow/contrib/lite:builtin_op_data",
"//tensorflow/contrib/lite:framework",
"//tensorflow/contrib/lite:schema_fbs_version",
"//tensorflow/contrib/lite:string",
"//tensorflow/contrib/lite:string_util",
"//tensorflow/contrib/lite/kernels:builtin_ops",
"//tensorflow/contrib/lite/schema:schema_fbs",
"//tensorflow/core:android_png_internal",
"//tensorflow/core:lib",
"//tensorflow/core:jpeg_internal",
],)
build裡邊的寫法當然跟makefile不一樣==,deps中包含的每乙個依賴都需要寫成庫。
這裡的string只有乙個標頭檔案,沒有.c或者.cc,這種貌似不用寫。(o_o)??
以string_util為例,string_util.h和string_util.cc都在tensorflow/contrib/lite目錄下邊。看一下tensorflow/contrib/lite目錄下的build檔案:
cc_library(
name = "string_util",
srcs = ["string_util.cc"],
hdrs = ["string_util.h"],
deps = [
":framework",
":string",
],)
這裡有乙個原始檔string_util.cc和乙個標頭檔案string_util.h,模仿其他makefile庫的寫法:include $(clear_vars)
local_src_files := \
string_util.cc
local_c_includes := \
externals/tensorflow \
externals/gemmlowp \
externals/tensorflow/flatbuffers/include\
externals/tensorflow/tensorflow/contrib/lite
local_cflags := -wall -werror -wextra -wno-unused-parameter
local_cflags += -wno-extern-c-compat -wno-mismatched-tags -wno-sign-compare -wno-unused-lambda-capture
local_cflags += -wno-missing-field-initializers
local_ldflags := -lpthread -ldl
local_cpp_extension := cc
local_static_libraries := libtflite_context\
libtflite_framework
local_shared_libraries := libtflite
local_module:= libtflite_stringutil
local_module_tags := eng
include $(build_shared_library)
這裡邊local_c_includes是原始檔中的標頭檔案所在的目錄,i.e. string_util.h所在的目錄,這個需要從根目錄開始寫,如果string_utils.h所在的目錄是a/b/c/d/e/f/string_utils.h。如果string_utils.cc中#include 「e/f/string_utils.h」,那麼local_c_includes應該寫為:local_c_includes := a/b/c/d。
local_static_libraries是當前庫編譯所依賴的靜態庫,寫到這需要看看string_util.cc檔案,string_util.cc檔案裡邊是這麼寫的:
#include #include #include "tensorflow/contrib/lite/context.h"
#include "tensorflow/contrib/lite/interpreter.h"
也就是說,context.h和interpreter.h需要新增進來。找一找他們對應的context.cc和interpreter.cc,看看他們是屬於哪個庫的:local_path := $(call my-dir)
include $(clear_vars)
local_src_files := \
context.c
local_c_includes := \
externals/tensorflow
local_static_libraries :=
local_cflags := -wall -werror -wextra -wno-unused-parameter
local_cflags += -wno-typedef-redefinition
local_module:= libtflite_context
local_module_tags := eng
include $(build_static_library)
可以看出來context.cc是屬於libtflite_context庫的,而且libtflite_context是乙個靜態庫。同理可以找到interpreter.cc被動態庫libtflite和靜態庫libtflite_framework編進去了,所以也要引入這兩個庫。在寫的時候用\作為換行符,注意\後邊不能有空格!!!否則會報錯:
commands commence before first target
大概就是這樣了,最後在當前資料夾下mm一下就可以看看寫的對不對了~目前是瞎寫一通。。。暫時能編譯過,先這樣吧,有問題再回來改=。=還有就是啥樣的檔案應該編譯成靜態庫,啥樣編成動態庫還不太明白==,明白之後再修改更新吧~~( ・´ω`・ )
~~~~~~~~~~~~~~~~~3.30更新~~~~~~~~~~~~~~~~~~~
關於具體都需要引進一些什麼庫,目測是用mm命令試一試,根據提示的錯誤總會知道的。。。(:3_ヽ)_
更新錯誤:
mm提示
make: *** no rule to make target
結果是因為local_src_files寫錯了╰(:з╰∠)_。。。
如果要編譯當前目錄下的檔案,那麼直接寫檔案的名字就好,不要寫路徑。
local_path := $(call my-dir)_
因為local_path 就是當前目錄,在當前目錄下再加上路徑當然就找不到需要編譯的檔案了。。φ( °-°)/ 跟我一起寫Makefile(1) 概述
概述 什麼是makefile?或許很多winodws的程式設計師都不知道這個東西,因為那些windows的ide都為你做了這個工作,但我覺得要作乙個好的和professional的程式設計師,makefile還是要懂。這就好像現在有這麼多的html的編輯器,但如果你想成為乙個專業人士,你還是要了解h...
一點一點學寫Makefile 1
相信很多linux開發者 都得自己來寫makefile,剛開始學習學寫這個的時候都會碰到很多困難,我之前沒有自己獨立完成過makefile,都是在公司已有的模板上新增。現在突然有乙個很大的想法就是從零開始寫makefile,這個部落格就是我的學習筆記。如下 cpp view plain copy i...
自己寫makefile簡易教程
前言 由於個人精力原因,我只寫makefile的內容,c語言以及shell指令又不了解的同學,請先學習c語言以及shell指令。寫單個檔案的makefile時,我們需要了解最基本的格式 target prerequistes.command target 是指生成的專案。prerequistes 是...