下载安装cmake
官网:cmake
克隆tensorflow官方库
git clone https://github.com/tensorflow/tensorflow.git tensorflow_src
编译tentsorflow-lite
mkdir tflite_build cd tflite_build cmake …/tensorflow_src/tensorflow/lite cmake --build . -j (or make)
引用示例
新建test项目
mkdir test cd test
新建hello.cpp
#include <cstdio>
#include "tensorflow/lite/interpreter.h"
int main() {
printf("Hello TensorFlow-Lite \n");
return 0;
}
创建并配置CMakeLists.txt
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(TEST)
ADD_COMPILE_OPTIONS(-Wall -Werror)
AUX_SOURCE_DIRECTORY(. SRC_LIST)
INCLUDE_DIRECTORIES(../tensorflow_src)
LINK_DIRECTORIES(../tflite_build)
ADD_EXECUTABLE(hello ${SRC_LIST})
TARGET_LINK_LIBRARIES(hello tensorflow-lite)
编译test
mkdir build cd build cmake … make
可能遇到的报错: g++版本过低需要升级g++
查看g++版本
g++ --version
升级g++
brew install gcc
修改~/.bash_profile
alias gcc=‘gcc-11’ alias g++=“g+±11” alias cc=“gcc-11” alias c++=“c+±11”
source
source ~/.bash_profile
执行cmake命令前用
export CC=/usr/local/bin/gcc export CXX=/usr/local/bin/g++
|