Error while including Caffe in C++ Project using c

2019-09-17 22:28发布

I want to include caffe in my project. This is the folder structure of the project:

.
├── AUTHORS
├── ChangeLog
├── cmake
│   ├── FindCaffe.cmake
│   └── FindCUDA.cmake
├── CMakeLists.txt
├── CMakeLists.txt.user
├── data
│   └── info.plist
├── deep-app.pro.user
├── LICENSE.txt
├── README.md
├── [reference]
│   ├── deep-app.pro
│   ├── deep-app.pro.user
│   ├── deployment.pri
│   ├── main.cpp
│   ├── main.qml
│   ├── Page1Form.ui.qml
│   ├── Page1.qml
│   └── qml.qrc
└── src
    ├── CMakeLists.txt
    ├── code
    │   └── main.cpp
    ├── icons.yml
    └── res
        ├── assets
        │   ├── assets.qrc
        │   ├── book-open-page.svg
        │   └── book-open.svg
        ├── icons
        │   ├── action_home.svg
        │   ├── action_list.svg
        │   ├── action_search.svg
        │   ├── action_settings.svg
        │   ├── file_cloud_done.svg
        │   ├── icons.qrc
        │   ├── maps_place.svg
        │   ├── navigation_check.svg
        │   └── social_school.svg
        └── qml
            ├── main.qml
            ├── Page1Form.ui.qml
            ├── Page1.qml
            └── qml.qrc

Here is the root/CMakeLists.txt:

project(generic-object-detection)

cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)
cmake_policy(VERSION 3.4.1)

ENABLE_LANGUAGE(C)

# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Instruct CMake to run moc and rrc automatically when needed
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# Apple-specific configuration
set(APPLE_SUPPRESS_X11_WARNING ON)

# Build flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -Werror -Wall -Wextra -Wno-unused-parameter -pedantic -std=c++11")

### Set libraries' locations
# Set Caffe
set(Caffe_DIR "/home/ubuntu/Libraries/caffe")
set(Caffe_INCLUDE_DIRS "/home/cortana/Libraries/caffe/include")
set(Caffe_LIBRARIES "/usr/lib/x86_64-linux-gnu/libcaffe.so")


# Disable debug output for release builds
if(CMAKE_BUILD_TYPE MATCHES "^[Rr]elease$")
    add_definitions(-DQT_NO_DEBUG_OUTPUT)
endif()

# Minimum version requirements
set(QT_MIN_VERSION "5.4.0")

# Find Qt5
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
             Core
             Qml
             Quick
             Concurrent)

# Find OpenCV 3.1
find_package(OpenCV 3.1.0 REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

# Find Boost
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})

# Find CUDA
FIND_PACKAGE(CUDA REQUIRED)

# Find Caffe
FIND_PACKAGE(Caffe REQUIRED)

if(UNIX)
    if(APPLE)
        set(MACOSX_BUNDLE_INFO_STRING "generic-object-detection")
        set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.mybitchinapp.generic-object-detection")
        set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME}-${PROJECT_VERSION}")
        set(MACOSX_BUNDLE_BUNDLE_NAME "generic-object-detection")
        set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION})
        set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION})
    else()
        # Assume linux
        # TODO: Install desktop and appdata files
    endif()
elseif(WIN32)
# Nothing to do here
endif()

add_subdirectory(src)

The file root/src/CMakeLists.txt:

file(GLOB_RECURSE SOURCES
            *.cpp *.h
            code/*.cpp code/*.h)

set(SOURCES ${SOURCES}
            res/assets/assets.qrc
            res/icons/icons.qrc
            res/qml/qml.qrc)

add_executable(deep-app ${SOURCES})

target_link_libraries(deep-app
                      Qt5::Core
                      Qt5::Qml
                      Qt5::Quick
                      Qt5::Concurrent
                      ${OpenCV_LIBS}
                      ${Boost_LIBRARIES}
                      ${CUDA_LIBRARIES})

set_target_properties(deep-app PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/data/Info.plist)

install(TARGETS deep-app
        RUNTIME DESTINATION bin
        DESTINATION ${CMAKE_INSTALL_BINDIR})

The error is:

CMake Error at CMakeLists.txt:55 (FIND_PACKAGE):
  By not providing "FindCaffe.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Caffe", but
  CMake did not find one.

  Could not find a package configuration file provided by "Caffe" with any of
  the following names:

    CaffeConfig.cmake
    caffe-config.cmake

  Add the installation prefix of "Caffe" to CMAKE_PREFIX_PATH or set
  "Caffe_DIR" to a directory containing one of the above files.  If "Caffe"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!

I have setup Caffe_DIR and other required variables. But it still gives the same errors. I removed the previous [cmake] cache so thats not the problem. I cant figure out how to resolve this problem and I need to use Caffe in the project. Please help.

标签: c++ cmake caffe
1条回答
爷、活的狠高调
2楼-- · 2019-09-17 23:10

You want to set your CMAKE_MODULE_PATH to location where cmake module files are located for Caffe project, which would be directory pointed to below:

.
├── AUTHORS
├── ChangeLog
├── cmake          <---------Set Caffe_DIR it to this directory
│   ├── FindCaffe.cmake
│   └── FindCUDA.cmake

If that doesn't work then you should set your Caffe_DIR to the above directory and make sure your rename the files under that directory to one of the names mentioned in the following error:

  Could not find a package configuration file provided by "Caffe" with any of
  the following names:

    CaffeConfig.cmake
    caffe-config.cmake
查看更多
登录 后发表回答