onnxruntime的include和lib文件都在/root/onnx下,如何编写cmakelists.txt导入onnxruntime让main.cpp能成功include <onnxruntime_cxx_api.h>
时间: 2023-09-03 19:15:25 浏览: 320
可以按照以下步骤编写CMakeLists.txt文件:
1. 在CMakeLists.txt文件中添加以下内容,设置onnxruntime的路径:
```cmake
set(ONNXRUNTIME_ROOT /root/onnx)
```
2. 添加头文件目录和库文件目录:
```cmake
include_directories(${ONNXRUNTIME_ROOT}/include)
link_directories(${ONNXRUNTIME_ROOT}/lib)
```
3. 添加onnxruntime库文件:
```cmake
add_library(onnxruntime SHARED IMPORTED)
set_target_properties(onnxruntime PROPERTIES IMPORTED_LOCATION ${ONNXRUNTIME_ROOT}/lib/libonnxruntime.so)
```
4. 链接onnxruntime库:
```cmake
target_link_libraries(your_project onnxruntime)
```
其中,`your_project`为你的项目名称。
完整的CMakeLists.txt文件示例:
```cmake
cmake_minimum_required(VERSION 3.0)
project(your_project)
set(CMAKE_CXX_STANDARD 11)
set(ONNXRUNTIME_ROOT /root/onnx)
include_directories(${ONNXRUNTIME_ROOT}/include)
link_directories(${ONNXRUNTIME_ROOT}/lib)
add_library(onnxruntime SHARED IMPORTED)
set_target_properties(onnxruntime PROPERTIES IMPORTED_LOCATION ${ONNXRUNTIME_ROOT}/lib/libonnxruntime.so)
add_executable(your_project main.cpp)
target_link_libraries(your_project onnxruntime)
```
阅读全文