Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CMAKE在dll中包含libtorch资源_Dll_Cmake_Libtorch - Fatal编程技术网

使用CMAKE在dll中包含libtorch资源

使用CMAKE在dll中包含libtorch资源,dll,cmake,libtorch,Dll,Cmake,Libtorch,我想在DLL中包含libtorch模型的权重 到目前为止,我已尝试将该文件转换为字节数组,并将其包含在.h文件中。不幸的是,这失败了,因为大型模型的编译失败 我当前的CMakeLists.txt如下: cmake_minimum_required(VERSION 3.0 FATAL_ERROR) project(DeepApp) find_package(Torch REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH

我想在DLL中包含libtorch模型的权重

到目前为止,我已尝试将该文件转换为字节数组,并将其包含在.h文件中。不幸的是,这失败了,因为大型模型的编译失败

我当前的CMakeLists.txt如下:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(DeepApp)

find_package(Torch REQUIRED)


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")



add_library(DeepApp SHARED DeepApp.cpp)
# add_executable(DeepApp DeepApp.cpp)

target_link_libraries(DeepApp "${TORCH_LIBRARIES}")

set_property(TARGET DeepApp PROPERTY CXX_STANDARD 14)

# 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 DeepApp
                     POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E copy_if_different
                     ${TORCH_DLLS}
                     $<TARGET_FILE_DIR:DeepApp>)
endif (MSVC)

cmake\u最低要求(3.0版致命错误)
项目(DeepApp)
查找包装(需要火炬)
设置(CMAKE_CXX_标志“${CMAKE_CXX_标志}${TORCH_CXX_标志}”)
添加库(DeepApp共享DeepApp.cpp)
#添加可执行文件(DeepApp DeepApp.cpp)
目标链接库(DeepApp“${TORCH\u库”)
set_属性(目标DeepApp属性CXX_标准14)
#建议在Windows上使用以下代码块。
#据https://github.com/pytorch/pytorch/issues/25457,
#需要复制DLL以避免内存错误。
if(MSVC)
文件(GLOB TORCH_dll“${TORCH_INSTALL_PREFIX}/lib/*.dll”)
添加自定义命令(目标应用程序)
后期构建
COMMAND${CMAKE_COMMAND}-E copy_如果不同
${TORCH_DLLS}
$)
endif(MSVC)
主要目的是隐藏模型的权重。我现在在主目录中有一个.pt文件,任何人都可以看到