Opencv与CUDA混合编译(CMake)

Opencv、CUDA与CMakeList.txt


#单独的Opencv编译如下

# cmake needs this line
cmake_minimum_required(VERSION 3.5)

# Define project name
project(test)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV 3.4.4 REQUIRED)

SET(CMAKE_CXX_STANDARD 11)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
link_directories("/home/fei/anaconda3/lib")
if(CMAKE_VERSION VERSION_LESS "3.5.1")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

# Declare the executable target built from your sources
add_executable(opencv_example main.cpp)

# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS})

#Opencv与CUDA的混合编译

# cmake needs this line
cmake_minimum_required(VERSION 3.5)

# Define project name
project(test)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV 3.4.4 REQUIRED)

SET(CMAKE_CXX_STANDARD 11)

option(ENABLE_CUDA "" ON)
find_package(CUDA REQUIRED)
if(CUDA_FOUND)
    include_directories(${CUDA_INCLUDE_DIRS})
endif()

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
link_directories("/home/fei/anaconda3/lib")
if(CMAKE_VERSION VERSION_LESS "3.5.1")
    # Add OpenCV headers location to your include paths
    include_directories(${OpenCV_INCLUDE_DIRS})
endif()

set(CMAKE_CXX_FLAGS_DEBUG " $ENV{CXXFLAGS} -std=c++11 -DDEBUG -DUSE_CUDA -DDLIB_NO_GUI_SUPPORT -g -O0 -w")
set(CMAKE_CXX_FLAGS_RELEASE " $ENV{CXXFLAGS} -std=c++11 -DNDEBUG -DUSE_CUDA -DDLIB_NO_GUI_SUPPORT -O3 -w")
set(CUDA_NVCC_FLAGS ${CMAKE_CXX_FLAGS_RELEASE} ${CUDA_NVCC_FLAGS} -gencode arch=compute_61,code=sm_61; --use_fast_math)

# Declare the executable target built from your sources
# add_executable(test TTT.cpp main2.cu)
# CUDA_ADD_LIBRARY(test SHARED main2.cu TTT.cpp)
CUDA_ADD_EXECUTABLE(test main2.cu TTT.cpp)

# Link your application with OpenCV libraries
target_link_libraries(test ${OpenCV_LIBS})

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值