c++ - OpenCV + 实感 : Visual Studio Link 2019 error

标签 c++ visual-studio opencv linker realsense

我无法将 OpenCV 与 Intel Realsense Viewer source code. 集成

注意事项: 我目前使用的是 Windows 10。

我正在使用 visual studio 2017.msvc 14.12

opencv 版本是 3.4.1 (windows pack),这是为您预先构建的版本。

我构建并安装了 intel realsense sdk from github .这是成功的。我还构建并成功安装了 OpenCV examples使用 openCV I downloaded .

当我尝试链接 OpenCV 时出现问题到 realsense viewer project

我尝试将 openCV 链接到 Intel Realsense Viewer 所遵循的步骤:

  1. 在visual studio中打开intel realsense sdk解决方案(就是那个.sln,叫做librealsense2)

  2. 转到 visual studio 的“解决方案资源管理器”面板中的 realsense-vewier 项目

  3. 右键单击项目“realsense-viewer”,然后选择属性

  4. 确保上面的 2 个下拉框有“x64”和“所有配置”

  5. 转到 C/C++ -> 常规选项(从左侧的白色框开始),然后转到“其他包含目录”

  6. 在目录 %OpenCVDownloadRoot%/build/include 和 %OpenCVDownloadRoot%/build/include/opencv 添加(这是示例 OpenCV 项目的配置

此时,openCV 中的一些函数没有在“realsense-viewer”项目中正确链接(这很奇怪,因为在 SDK 中的 OpenCV 项目中工作,即使属性相同。错误如下: enter image description here

然后我执行了一些额外的步骤,看看是否可以让它工作。

  1. 在属性对话框(我们刚才所在的那个)中,不要选择 C/C++,而是选择“链接器”

  2. 在“其他库目录”选项中,添加 %OpenCVDownloadRoot%/build/x64/vc15/lib

  3. 在“链接器”属性中,搜索输入(链接器 -> 输入)

  4. 在“附加依赖项”选择中添加“opencv_world341d.lib”。

现在我们得到一个完全不同的错误: enter image description here

现在 realsense 库不被识别。除上述内容外,未修改其他属性。我可以确认第 10 步导致了所有这些错误。即使我在执行完所有步骤后反转步骤 10 的操作,上述错误仍然存​​在 -> 这一定是 visual studio 错误。

关于如何让 OpenCV 3.4.1 + realsense-viewer(来自 SDK)在 visual studio 2017 中工作的任何帮助或提示?

编辑:我已经读过: What is an undefined reference/unresolved external symbol error and how do I fix it?

但我已经正确链接了 glfw 和所有其他需要链接的东西,以便错误消息消失。我认为问题可能是 intel 的错误,或者是 vs 的错误,需要解决方法

最佳答案

在公园散步后找到的解决方案(假设您使用的是 Windows 10,项目使用 visual studio 2017):

进入您本地的 librealsense 项目文件夹

转到C:\Users\yourName\to\your\local\realsense\folder\librealsense\tools\CMakeLists.txt

将此添加到文件末尾:

find_package(OpenCV REQUIRED)

list(APPEND DEPENDENCIES realsense2 ${OpenCV_LIBS})

所以整个文件是这样的:

minimum required cmake version: 3.1.0 cmake_minimum_required(VERSION 3.1.0)

project(RealsenseTools)

Save the command line compile commands in the build output set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

View the makefile commands during build

set(CMAKE_VERBOSE_MAKEFILE on)

This parameter is meant for disabling graphical examples when building for

save-to-disk targets. option(BUILD_GRAPHICAL_EXAMPLES "Build graphical examples." ON)

include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") elseif(COMPILER_SUPPORTS_CXX0X) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") endif()

if(BUILD_GRAPHICAL_EXAMPLES) find_package(OpenGL) if(NOT OPENGL_FOUND) message(FATAL_ERROR "\n\n OpenGL package is missing!\n\n") endif()

set(DEPENDENCIES realsense2 ${OPENGL_LIBRARIES})

if(WIN32)
    list(APPEND DEPENDENCIES glfw3)
else()
    # Find glfw header
    find_path(GLFW_INCLUDE_DIR NAMES GLFW/glfw3.h
        PATHS /usr/X11R6/include
              /usr/include/X11
              /opt/graphics/OpenGL/include
              /opt/graphics/OpenGL/contrib/libglfw
              /usr/local/include
              /usr/include/GL
              /usr/include
    )
    # Find glfw library
    find_library(GLFW_LIBRARIES NAMES glfw glfw3
            PATHS /usr/lib64
                  /usr/lib
                  /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}
                  /usr/local/lib64
                  /usr/local/lib
                  /usr/local/lib/${CMAKE_LIBRARY_ARCHITECTURE}
                  /usr/X11R6/lib
    )
    if(APPLE)
        find_library(COCOA_LIBRARY Cocoa)
        find_library(IOKIT_LIBRARY IOKit)
        find_library(COREVIDEO_LIBRARY CoreVideo)
        LIST(APPEND DEPENDENCIES ${COCOA_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY})
    endif()
    list(APPEND DEPENDENCIES m ${GLFW_LIBRARIES} ${LIBUSB1_LIBRARIES})
    include_directories(${GLFW_INCLUDE_DIR})
endif() else()
set(DEPENDENCIES realsense2)
if(NOT WIN32)
    list(APPEND DEPENDENCIES m ${LIBUSB1_LIBRARIES})
endif() endif()

allow this project to access opencv find_package(OpenCV REQUIRED)

find_package(OpenCV REQUIRED) set(DEPENDENCIES realsense2 ${OpenCV_LIBS})

add_subdirectory(terminal) add_subdirectory(fw-logger) add_subdirectory(enumerate-devices) add_subdirectory(realsense-viewer) add_subdirectory(data-collect) add_subdirectory(depth-quality) add_subdirectory(rosbag-inspector)

然后使用cmake gui重建项目

关于c++ - OpenCV + 实感 : Visual Studio Link 2019 error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49332616/

相关文章:

c++ - Mac 上 C++ 中 for 循环的奇怪行为

c++ - visual studio 中的 Onexit.c 错误?

c++ - 切割圆的底部

c++ - OpenCV 人物检测样本崩溃

android - 一些奇怪的安卓错误

c# - 在后台运行程序 Wix

c++ - C/C++中的NaN比较规则

c++ - Qt 4.8.6/Linux Mint 中没有西里尔字母

C 代码无法在 Windows 上运行 (Visual Studio 2013)

python - 如何基于边缘检测对图像重新着色(Canny)