Windows10 64位下运行hello-realsense程序

一、下载RealSense源码

下载地址看 五、参考资料及下载地址
在这里插入图片描述

二、下载c++编译器

在这里插入图片描述

三、下载cmake

在这里插入图片描述

四、编写CMakeLists.txt文件及运行cpp文件

解压RealSense源码压缩包,在所在的目录下创建CMakeLists.txt文件:

# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2019 Intel Corporation. All Rights Reserved.
#  minimum required cmake version: 3.1.0
cmake_minimum_required(VERSION 3.1.0)

project(RealsenseExamplesHelloRealSense)

# 设置.lib和.dll文件所在的目录
if(WIN32)
    if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
        set(LIBRARY_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\lib\\x64")          # TODO: Update this variable to correct path - folder where realsense2.lib is found
        set(DLL_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\bin\\x64")              # TODO: Update this variable to correct path - folder where realsense2.dll is found
    else()
        set(LIBRARY_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\lib\\x86")          # TODO: Update this variable to correct path - folder where realsense2.lib is found
        set(DLL_DIR "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\bin\\x86")              # TODO: Update this variable to correct path - folder where realsense2.dll is found
    endif()
    set(PROJECT_BINARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/\$\(Configuration\)")                # TODO: Update this variable to correct path - folder to which your project will compile
    set(ADDITIONAL_INCLUDE_DIRS "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\include")   # TODO: Update this variable to correct path - folder where librealsense2 folder is found
endif()

# 在.lib中找realsense2库
find_library(REALSENSE2_FOUND realsense2 HINTS ${LIBRARY_DIR} REQUIRED)
if(NOT REALSENSE2_FOUND)
    SET(REALSENSE2_FOUND "realsense2")
    message(WARN "Failed to find_library(realsense2)")
endif()

# 添加可执行文件
add_executable(rs-hello-realsense rs-hello-realsense.cpp)

target_link_libraries(rs-hello-realsense ${DEPENDENCIES})
target_link_libraries(rs-hello-realsense ${REALSENSE2_FOUND})

# 设置头文件所在的目录
set(ADDITIONAL_INCLUDE_DIRS "C:\\Program Files (x86)\\Intel RealSense SDK 2.0\\include")
include_directories(rs-hello-realsense ${ADDITIONAL_INCLUDE_DIRS})

# set_property(TARGET ...) 相当于set_target_properties(...),在给定的作用域中设置一个命名的属性。
set_property(TARGET rs-hello-realsense PROPERTY CXX_STANDARD 11)
set_target_properties (rs-hello-realsense PROPERTIES FOLDER "Examples")

# 把realsense2.dll复制到当前目录下
if(WIN32)
message(STATUS "Adding Post build script to copy realsense2.dll to project's binary folder")
message(STATUS "Will try to copy from ${DLL_DIR} to ${PROJECT_BINARY_OUTPUT_PATH}")
add_custom_command(TARGET rs-hello-realsense POST_BUILD        # Adds a post-build event to rs-hello-realsense
    COMMAND ${CMAKE_COMMAND} -E copy_if_different              # which executes "cmake - E copy_if_different..."
        "${DLL_DIR}/realsense2.dll"                            # <--this is in-file
        ${PROJECT_BINARY_OUTPUT_PATH})                 # <--this is out-file path
endif()

# install(TARGETS MyLib
#         EXPORT MyLibTargets 
#         LIBRARY DESTINATION lib  # 动态库安装路径
#         ARCHIVE DESTINATION lib  # 静态库安装路径
#         RUNTIME DESTINATION bin  # 可执行文件安装路径
#         PUBLIC_HEADER DESTINATION include  # 头文件安装路径
#         )
install(TARGETS rs-hello-realsense RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

文件目录:
在这里插入图片描述
构建程序及运行:

mkdir build && cd build
cmake -G "MinGW Makefiles" ../
mingw32-make.exe all
./rs-hello-realsense.exe

五、参考资料及下载地址

  1. RealSense源码下载地址
  2. mingw64下载地址
  3. CMake下载地址
  4. CMakeLists.txt配置realsense的dll和lib文件
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值