本文介绍了使用cmake在C ++项目中包含Caffe时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的项目中加入咖啡。这是项目的文件夹结构:

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

这是 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)

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

错误是:

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!

我已经设置了 了Caffe_DIR和其他必需项变量。但是它仍然给出相同的错误。我删除了以前的[cmake]缓存,所以那不是问题。我不知道如何解决此问题,我需要在项目中使用Caffe。请帮忙。

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.

推荐答案

您要将 CMAKE_MODULE_PATH 设置到以下位置cmake module 文件位于 Caffe 项目中,该文件将指向以下目录:

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

如果这不起作用,那么您应该将您的 Caffe_DIR 设置到上述目录,并确保将该目录下的文件重命名为以下错误中提到的名称之一:

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

这篇关于使用cmake在C ++项目中包含Caffe时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 11:55