Skip to content

Instantly share code, notes, and snippets.

@tejainece
Created October 15, 2025 08:41
Show Gist options
  • Save tejainece/958d76f83c6987d509fc942225211115 to your computer and use it in GitHub Desktop.
Save tejainece/958d76f83c6987d509fc942225211115 to your computer and use it in GitHub Desktop.
Compile libtorch example
cmake_minimum_required(VERSION 3.31.6)
project(libtorch_examples)
set(libtorch_VERSION 2.8.0)
find_package(Torch ${libtorch_VERSION} PATHS ../libtorch_linux)
if(NOT Torch_FOUND)
else()
message(STATUS "libtorch ${libtorch_VERSION} - found")
endif()
macro(add_example name)
add_executable(${name} ${name}.cpp)
target_include_directories(${name} PRIVATE ../libtorch_linux/include)
target_include_directories(${name} PRIVATE ../libtorch_linux/include/torch/csrc/api/include)
target_link_libraries(${name} ${TORCH_LIBRARIES})
endmacro()
add_example(ctorch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment