Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Having trouble adding include directories
I'm trying to set up a simple test project, to unit test a change I'm working on. The change is to a file inside some existing project.
I've tried to set up the includes as the original has it, but I'm still getting compiler errors complaining that an included file can't be found. (This project uses a homebrew build system other than CMake, so I couldn't just look in its CMake files to see how it did it).
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.16.2)
project(Testing LANGUAGES CXX)
set(sources
/Users/me/Projects/OtherProject/repo/src/FooBarAPI/Blah.cpp
)
include_directories(/Users/me/Projects/OtherProject/repo/src/FooBarAPI/)
add_executable(test main.cpp ${sources})
But make spits out:
In file included from /Users/me/Projects/Testing/repo/main.cpp:1:
/Users/me/Projects/OtherProject/repo/src/FooBarAPI/Blah.hpp|3 col 10| fatal error: 'BeepBoop.hpp' file not found
#include "BeepBoop.hpp"
^~~~~~~~~~~~~~~~~
1 error generated.
Indeed, if I look in the Makefile which CMake generated, there's no FooBarAPI anywhere in there. Isn't that what include_directories
is for? What am I missing?
1 answer
Ah.
There's a good reason the compiler says it can't find the file: it's not there.
In my particular case, BeepBoop.hpp actually gets automatically generated from other files by the ordinary build process, and I didn't realise this.
include_directories
is perfectly correct.
1 comment thread