open-mmlab / mmdeploy

OpenMMLab Model Deployment Framework
https://mmdeploy.readthedocs.io/en/latest/
Apache License 2.0
2.77k stars 636 forks source link

CMakelist.txt of mmdeploy example is missing links to .h and .so files #174

Closed starhou closed 2 years ago

starhou commented 2 years ago

when I run the Run MMDeploy SDK Demo

cmake -DOpenCV_DIR=path/to/OpenCV/lib/cmake/OpenCV \
      -DMMDeploy_DIR=${MMDEPLOY_DIR}/build/install/lib/cmake/MMDeploy ..
make object_detection

I got an error that can't find 'detect.h'

Bug fix

It was solved after I add

include_directories(../include/c)
include_directories(../include/cpp/core)
include_directories(../include/cpp/experimental)

link_directories(/home/hxy/hxy/localwork/mmdeploy/build/install/lib)

to the CMakeLists.txt in path .../localwork/mmdeploy/build/install/example

lzhangzz commented 2 years ago

Hi @starhou,

Can you provide more information on reproducing the problem (e.g. corresponding CMakeLists.txt, CMake verion & OS version)?

Those directories are handled by targets in the mmdeploy cmake package so that any target depend on mmdeploy libs will include them automatically.

starhou commented 2 years ago

CMakeLists.txt‘s path is mmdeploy/build/install/example after compiled using below

mkdir build && cd build
cmake .. \
    -DMMDEPLOY_BUILD_SDK=ON \
    -DCMAKE_CXX_COMPILER=g++-7 \
    -DONNXRUNTIME_DIR=/path/to/onnxruntime \
    -DMMDEPLOY_TARGET_DEVICES=cpu \
    -DMMDEPLOY_TARGET_BACKENDS=ort \
    -DMMDEPLOY_CODEBASES=all
cmake --build . -- -j$(nproc) && cmake --install .

I used Ubuntu 20.04, cmake 3.20 , it seems the auto-generated CMakeLists do not contain these two paths.

mmdeploy/build/install/include
mmdeploy/build/install/lib

The erros occurs when run below

cmake -DOpenCV_DIR=path/to/OpenCV/lib/cmake/OpenCV \
      -DMMDeploy_DIR=${MMDEPLOY_DIR}/build/install/lib/cmake/MMDeploy ..
make object_detection
lzhangzz commented 2 years ago

I failed to reproduce the problem following your steps.

Below is a slightly modified version of the example CMakeLists.txt. I added line 9 to print all mmdeploy libs obtained from find_package(MMDeploy).

# Copyright (c) OpenMMLab. All rights reserved.
cmake_minimum_required(VERSION 3.14)
project(mmdeploy-example)

find_package(OpenCV REQUIRED)
find_package(MMDeploy REQUIRED)

# Add this line
message(STATUS "${MMDeploy_LIBS}")

function(add_example name)
  add_executable(${name} ${name}.cpp)
  target_link_libraries(${name} ${MMDeploy_LIBS} -Wl,--disable-new-dtags
  opencv_imgcodecs opencv_imgproc opencv_core)
endfunction()

add_example(image_classification)
add_example(object_detection)
add_example(image_restorer)
add_example(image_segmentation)
add_example(ocr)

Can you try it on your configuration by re-running cmake to see what's printed? It's crucial to see whether MMDeploy_LIBS contains valid targets to further diagnose the problem.

starhou commented 2 years ago

Thank you, maybe it's another problem with my environment, I installed it many times before I succeeded, but it finally worked