Код: Выделить всё
MyLibtorchProject/
├── CMakeLists.txt
├── main.cpp
├── libtorch/
└── build/
Код: Выделить всё
cmake_minimum_required(VERSION 3.10)
project(MyLibtorchProject)
# Set the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Set the LibTorch directory path
set(Torch_DIR "C:/Desktop/Audio_C++_JUCE/MyLibtorchProject/libtorch/share/cmake/Torch")
# Find the LibTorch package
find_package(Torch REQUIRED)
# Add the executable target
add_executable(MyLibtorchProject main.cpp)
# Link LibTorch to your executable
target_link_libraries(MyLibtorchProject "${TORCH_LIBRARIES}")
# Ensure the target uses C++17 features
target_compile_features(MyLibtorchProject PRIVATE cxx_std_17)
# Set the C++ flags required by LibTorch
set_property(TARGET MyLibtorchProject PROPERTY CXX_STANDARD 14)
set_property(TARGET MyLibtorchProject PROPERTY CXX_STANDARD_REQUIRED ON)
# Set debug and release configurations if needed
if (MSVC)
# Enable multithreading and increase the number of sections in object files
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj /std:c++17")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++17")
endif()
Код: Выделить всё
#include
#include
int main() {
// Create a simple tensor
torch::Tensor tensor = torch::rand({2, 3});
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79084040/how-to-set-up-cmakelists-txt-for-libtorch-in-a-c-project[/url]