Home > Net >  How to write a simple CMAKELISTS for OpenViNO to my C programme in Linux
How to write a simple CMAKELISTS for OpenViNO to my C programme in Linux

Time:02-16

I have been trying very hard to set up OpenVINO for my C programme. But the official guide was very unclear to me (partially because I am a very beginner). I was struggling to understand how it finds "InferenceEngine_LIBRARIES" (or "OpenCV_LIBS") without even defining it.

I have tried to understand some examples in GitHub but sadly many of them are for older versions. I was wondering if I could have a minimum demo of the CMakeLists.txt to use the OpenVINO. Thank you very much.

--- Updates ---

Thanks for the comments. I understand some things were handled by CMake behind the scene. Going to the point, here is my CMakeLists file

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})

And my "main.cpp" is just

#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;
}

But When I build it, I got the following error, and I would like to ask for any help. Thank you very much!

====================[ 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.

CodePudding user response:

The linker error shows that it cannot find the TBB symbols. The TBB library should be pointed to by the TBB_DIR variable. You don't have to set those variables manually using cmake's set() function. Instead - in the shell where you compile your own app - you can source OpenVINO's setupvars.sh script. Just run something like: source /opt/intel/openvino_2021/bin/setupvars.sh and re-run the compiler. I can see you're using CLion, not the terminal directly. In that case you can try adding the variable manually. The TBB location might be slightly different between the OV versions but in general it should point to a subdirectory of /opt/intel/openvino_2021 - just browse the installation directory and try to find it or source setupvars.sh in the terminal and copy the TBB_DIR env var value to your IDE.

  • Related