Hello, just started working with CMake and was going through the tutorial fine until step 2 exercise 1, Creating a library. I completed all the TODOs but when I go to build the solution, I get an error:
[project path]Step2\tutorial.cpp(8,10): error C1083: Cannot open include file: 'MathFunctions.h': No such file or directory [[project path]\Step2\Step2_build\Tutorial.vcxproj]
.
I am using powershell to run the commands and even tried it with the exact same commands and file, yet I’m still getting an error.
Here is what I have added for top level “CMakeLists.txt”:
// ...omitted code...
# TODO 2: Use add_subdirectory() to add MathFunctions to this project
add_subdirectory(MathFunctions)
# add the executable
add_executable(Tutorial tutorial.cpp)
# TODO 3: Use target_link_libraries to link the library to our executable
target_link_libraries(Tutorial PUBLIC MathFunctions)
# TODO 4: Add MathFunctions to Tutorial's target_include_directories()
# Hint: ${PROJECT_SOURCE_DIR} is a path to the project source. AKA This folder!
# add the binary tree to the search path for include files to find TutorialConfig.h
target_include_directories(Tutorial PUBLIC
"${PROJECT_BINARY_DIR}"
"${PROJECT_BINARY_DIR}/MathFunctions"
)
Here is what I have in “MathFunctions/CMakeLists.txt”:
add_library(MathFunctions
MathFunctions.cpp
mysqrt.cpp
)
My tutorial.cpp also has the “MathFunctions.h” include.
I also noticed when opening up the solution in Visual Studio that MathFunctions is setup as another project in the solution. Is that supposed to be correct? What am I missing that causes the error?