c++ - 使用 cmake 在 C++ 项目中包含 Caffe 时出错

标签 c++ cmake caffe

我想在我的项目中包含 caffe。这是项目的文件夹结构:

.
├── 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。请帮忙。

最佳答案

您想将 CMAKE_MODULE_PATH 设置为 Caffe 项目的 cmake module 文件所在的位置,这将是指向下面的目录:

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

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

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

    CaffeConfig.cmake
    caffe-config.cmake

关于c++ - 使用 cmake 在 C++ 项目中包含 Caffe 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39760895/

相关文章:

c++ - 将 NON-POD 类型传递给 Variadic 函数是未定义的行为?

c++ - ofstream - 需要在 close() 操作后删除对象句柄吗?

linux - CMake:找不到没有绝对路径的库

python - Caffe:如何通过代码获取 `solver.prototxt`参数?

c++ - 连接c++和Mysql

c++ - 运算符的递归应用->

c++ - 如何将 QSerialPort 模块添加到 CMake 中?

c - 当 C 中有多个实现共享同一接口(interface)时,如何编写 CMakeLists.txt 或 Makefile 以避免冲突?

machine-learning - 您可以仅复制网络前 3 层的权重吗?不完全是微调,但几乎是 reshape

neural-network - 在 Caffe 框架中修改 ReLU 中的阈值