Notifications
Q&A

Having trouble adding include directories

+2
−0

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?

Why should this post be closed?

0 comments

1 answer

+3
−0

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.

0 comments

Sign up to answer this question »