0

So here is what my project looks like, for reference:

+ <root>
  + build
  + inc
    + libsm64
      + libsm64.hpp
  + src
    + libsm64.cpp
    + CMakeLists.txt
  + CMakeLists.txt

The top-level CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(libsm64)

# add source.
add_subdirectory(src)

and the CMakeLists.txt for /src:

add_library(libsm64 libsm64.cpp ../inc/libsm64/libsm64.hpp)
target_include_directories(libsm64 PRIVATE ../inc)

Both Visual Studio 2019 and VSCode will give me an error in libsm64.cpp saying that it cannot open libsm64/libsm64.hpp. Why?

EDIT: Even if I replace the relative directory references with absolute references i.e. ${libsm64_PROJECT_DIR}/inc/libsm64/libsm64.hpp it won't work.

itzjackyscode
  • 970
  • 9
  • 27
  • In Visual Studio look at your Include directories in your project settings to see what was added. – drescherjm May 15 '21 at 13:27
  • It doesn't have a .sln file, it was created using visual studio's cmake integration. Should I use cmake to generate a .sln? – itzjackyscode May 15 '21 at 15:25
  • I have CMake generate Visual Studio project files always. – drescherjm May 16 '21 at 00:10
  • I believe the error has nothing to do with `${libsm64_PROJECT_DIR}/inc/libsm64/libsm64.hpp` or `add_library(libsm64 libsm64.cpp ../inc/libsm64/libsm64.hpp)` – drescherjm May 16 '21 at 00:11
  • 1
    Wait a minute is ***saying that it cannot open libsm64/libsm64.hpp.*** a compile error? or you can't open the file in the IDE? – drescherjm May 16 '21 at 00:12

1 Answers1

0

See here and here.

You want to add a currentDir entry, sorta like this:

"currentDir": "${workspaceRoot}"

Visual Studio apparently ain't that smart.

Kevin
  • 398
  • 2
  • 7