libtorch opecv c++ cmake clion

使用clion写c++,使用cmake编译 opencv和libtorch,使用的是window11系统。

    1. 其中项目名称叫torch_use0124
    1. libtorch文件夹路径为:C:/Users/yuanz/Downloads/cpp_library/libtorch
    1. opencv文件夹路径为:C:/Users/yuanz/Downloads/cpp_library/opencv
cmake_minimum_required(VERSION 3.21)
project(torch_use0124)

set(CMAKE_CXX_STANDARD 17)

add_executable(torch_use0124 main.cpp Darknet.cpp Darknet.h)


# opencv
set(OpenCV_DIR C:/Users/yuanz/Downloads/cpp_library/opencv/build/x64/vc15/lib)
include_directories(C:/Users/yuanz/Downloads/cpp_library/opencv/sources/include)
find_package(OpenCV REQUIRED )
target_link_libraries(torch_use0124 ${OpenCV_LIBS})



# libtorch

set(CMAKE_PREFIX_PATH C:/Users/yuanz/Downloads/cpp_library/libtorch)
include_directories(C:/Users/yuanz/Downloads/cpp_library/libtorch/include)
include_directories(C:/Users/yuanz/Downloads/cpp_library/libtorch/include/torch/csrc/api/include)


find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

target_link_libraries(torch_use0124 "${TORCH_LIBRARIES}")
set_property(TARGET torch_use0124 PROPERTY CXX_STANDARD 17)

# The following code block is suggested to be used on Windows.
# According to https://github.com/pytorch/pytorch/issues/25457,
# the DLLs need to be copied to avoid memory errors.
if (MSVC)
    file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
    add_custom_command(TARGET torch_use0124
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_if_different
            ${TORCH_DLLS}
            $<TARGET_FILE_DIR:torch_use0124>)
endif (MSVC)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuanzhoulvpi

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值