如何在 Linux 中为我的 C++ 程序编写一个简单的 OpenViNO CMAKELISTS

How to write a simple CMAKELISTS for OpenViNO to my C++ programme in Linux

我一直在努力为我的 C++ 程序设置 OpenVINO。但是 official guide 对我来说非常不清楚(部分原因是我是一个非常初学者)。我一直在努力理解它是如何在没有定义它的情况下找到“InferenceEngine_LIBRARIES”(或“OpenCV_LIBS”)的。

我试图理解 GitHub 中的一些示例,但遗憾的是,其中许多是针对旧版本的。我想知道我是否可以获得 CMakeLists.txt 的最低演示以使用 OpenVINO。非常感谢。

--- 更新 ---

感谢您的评论。我知道有些事情是由 CMake 在幕后处理的。进入正题,这是我的 CMakeLists 文件

cmake_minimum_required(VERSION 3.21)
project(openvino)
set(CMAKE_CXX_STANDARD 14)

# OpenVINO
set(ngraph_DIR "/opt/intel/openvino_2021/deployment_tools/ngraph/cmake")
find_package(ngraph REQUIRED)
set(InferenceEngine_DIR "/opt/intel/openvino_2021/deployment_tools/inference_engine/share")
find_package(InferenceEngine REQUIRED)
set(OpenCV_DIR "/opt/intel/openvino_2021/opencv/cmake")
find_package(OpenCV REQUIRED)

add_executable(openvino main.cpp)
target_link_libraries(
    ${PROJECT_NAME}
    PRIVATE ${InferenceEngine_LIBRARIES}
    ${OpenCV_LIBS}
    ${NGRAPH_LIBRARIES})

而我的“main.cpp”只是

#include <inference_engine.hpp>
int main() {
    InferenceEngine::Core core;
    InferenceEngine::ExecutableNetwork executable_network;
    executable_network = core.LoadNetwork("./models/decoder.xml", "CPU");
    auto infer_request = executable_network.CreateInferRequest();
    return 0;
}

但是当我构建它时,出现了以下错误,我想寻求任何帮助。非常感谢!

====================[ Build | openvino | Debug ]================================
/home/kent/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/213.6777.58/bin/cmake/linux/bin/cmake --build /media/kent/DISK2/CLionProjects/openvino/cmake-build-debug --target openvino
[2/2] Linking CXX executable openvino
FAILED: openvino 
: && /usr/bin/c++ -g  CMakeFiles/openvino.dir/main.cpp.o -o openvino  -Wl,-rpath,/opt/intel/openvino_2021/opencv/lib:/opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64:/opt/intel/openvino_2021/deployment_tools/ngraph/lib  /opt/intel/openvino_2021/opencv/lib/libopencv_gapi.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_highgui.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_ml.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_objdetect.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_photo.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_stitching.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_video.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_videoio.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_dnn.so.4.5.3  /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so  /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine_c_api.so  /opt/intel/openvino_2021/deployment_tools/ngraph/lib/libngraph.so  /opt/intel/openvino_2021/opencv/lib/libopencv_imgcodecs.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_calib3d.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_features2d.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_flann.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_imgproc.so.4.5.3  /opt/intel/openvino_2021/opencv/lib/libopencv_core.so.4.5.3 && :
/usr/bin/ld: warning: libtbb.so.2, needed by /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_max_concurrency(tbb::interface7::task_arena const*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::internal_grow_by(unsigned long, unsigned long, void (*)(void*, void const*, unsigned long), void const*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::~concurrent_vector_base_v3()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::NFS_Allocate(unsigned long, unsigned long, void*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::concurrent_vector_base_v3::internal_clear(void (*)(void*, unsigned long))'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_current_slot()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::allocate_via_handler_v3(unsigned long)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::NFS_Free(void*)'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::thread_get_id_v3()'
/usr/bin/ld: /opt/intel/openvino_2021/deployment_tools/inference_engine/lib/intel64/libinference_engine.so: undefined reference to `tbb::internal::deallocate_via_handler_v3(void*)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

链接器错误显示它找不到 TBB 符号。 TBB_DIR 变量应指向 TBB 库。您不必使用 cmake 的 set() 函数手动设置这些变量。相反 - 在您编译自己的应用程序的 shell 中 - 您可以获取 OpenVINO 的 setupvars.sh 脚本。只是 运行 类似的东西:source /opt/intel/openvino_2021/bin/setupvars.sh 和 re-run 编译器。 我可以看到您正在使用 CLion,而不是直接使用终端。在这种情况下,您可以尝试手动添加变量。 OV 版本之间的 TBB 位置可能略有不同,但通常它应该指向 /opt/intel/openvino_2021 的子目录 - 只需浏览安装目录并尝试在终端中找到它或来源 setupvars.sh 并复制TBB_DIR 您的 IDE.

环境变量值