arm平台调用基于tiny_publish静态库的动态库,报找不到符号的错误
Created by: zhizunbao-y
平台 :jetson nano + ubuntu16.04 Paddle-Lite : release/v2.0.0-beta2 tiny_publish 目录结构 其中include 和 lib为编译生成,src中包含两个文件engine.cpp和engine.h engine.cpp:
#ifndef ENGINE_H
#define ENGINE_H
#include <stdlib.h>
#include<sys/time.h>
#include<iostream>
#include<string>
#include<vector>
#include "paddle_api.h" // NOLINT
#include "paddle_use_kernels.h" // NOLINT
#include "paddle_use_ops.h" // NOLINT
#include "paddle_use_passes.h" // NOLINT
using namespace std;
using namespace paddle::lite_api; // NOLINT
shared_ptr<PaddlePredictor> spredictor;
struct timeval start_time, end_time;
typedef struct Result{
double time;
float outputs[3];
}Res,*ResPointer;
int init(char * model_path,int power_mode=0, int num_thread = 1);
ResPointer infer(float * input);
#endif
engine.cpp:
#include"engine.h"
using namespace std;
using namespace paddle::lite_api; // NOLINT
int64_t ShapeProduction(const shape_t& shape) {
int64_t res = 1;
for (auto i : shape) res *= i;
return res;
}
int init(char* model, int power_mode, int num_thread){
string model_path=model;
MobileConfig config;
config.set_model_dir(model); //model dir
PowerMode mode = PowerMode(power_mode);
config.set_power_mode(mode); //power mode
config.set_threads(num_thread); //threads
shared_ptr<PaddlePredictor> predictor = CreatePaddlePredictor<MobileConfig>(config);
if (predictor!=NULL){
spredictor = move(predictor);
return 1;
}
return -1;
}
ResPointer infer(float * input){
ResPointer rp = (ResPointer)malloc(sizeof(Res));
unique_ptr<Tensor>input_tensor(move(spredictor->GetInput(0)));
input_tensor->Resize({1, 3, 224, 224});
auto* data = input_tensor->mutable_data<float>();
for (int i = 0; i < ShapeProduction(input_tensor->shape()); ++i) {
data[i] = *(input+i);
}
gettimeofday(&start_time, NULL); //gettimeofday(&start,&tz);结果一样
spredictor->Run();
gettimeofday(&end_time, NULL);
unique_ptr<const Tensor> output_tensor(move(spredictor->GetOutput(0)));
for (int i = 0; i < ShapeProduction(output_tensor->shape()); i ++) {
rp->outputs[i]= output_tensor->data<float>()[i];
}
rp->time=(end_time.tv_sec-start_time.tv_sec)*1000+(end_time.tv_usec-start_time.tv_usec)/1000;
return rp;
}
CmakeList.txt:
cmake_minimum_required(VERSION 3.5.1)
project(engine)
message(${PROJECT_SOURCE_DIR})
set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(LIB_DIR ${PROJECT_SOURCE_DIR}/lib)
set(SRC ${PROJECT_SOURCE_DIR}/src)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories(${INCLUDE_DIR})
link_directories(${LIB_DIR})
add_library(engine SHARED ${SRC}/engine.cpp)
target_link_libraries(engine paddle_api_light_bundled)
编译成功 使用python ctypes模块调用时出现undefined symbol的错误,使用ldd -r libengin.so结果如下: