i am encountering a problem where in my uneducated opinion, the includes should already be included in the cmake file using
target_include_directories(testing PUBLIC "${TORCH_INCLUDE_DIRS}")
but cannot be opened in the .cpp file, that is in the same directory as the cmake file. here are what my files look like:
CMakelists.txt
cmake_minimum_required(VERSION 3.18)
project(testing)
list(APPEND CMAKE_PREFIX_PATH "Downloads/path/to/libtorch")
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
add_executable(testing test.cpp)
target_link_libraries(testing ${TORCH_LIBRARIES})
target_include_directories(testing PUBLIC "${TORCH_INCLUDE_DIRS}") #does not build without scope keyword
set_property(TARGET testing PROPERTY CXX_STANDARD 17)
if (MSVC) # I am on Visual Studio
file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
add_custom_command(TARGET testing
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${TORCH_DLLS}
$<TARGET_FILE_DIR:testing>)
endif (MSVC)
test.cpp
#include <torch/torch.h>
#include <iostream>
int main() {
torch::Tensor tensor = torch::rand({ 2, 3 });
std::cout << tensor << "\n";
}
in test.cpp it tells me " cannot open source file “torch/torch.h” "
CppProperties.json points to the right torch folder and torch.h is present inside. it was explicitly included there as a fix suggested by visual studio, and removing it does not change the outcome
my question is: why would it not be able to open the file? i have tried opening Visual Studio in Administrator mode, and it did not help.
i have searched the internet far and wide, including this forum, stackoverflow and reddit, but i have not found a solution to my problem so far.