Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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.

Comments on Having trouble adding include directories

Post

Having trouble adding include directories

+2
−2

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?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (2 comments)
General comments
alex‭ wrote almost 4 years ago

Never put absolute paths in your lists file. There are so many alternatives: import OtherProject with find_package, add its CMake build to yours with add_subdirectory, include it as a git submodule and use relative paths, etc.

Hyperlynx‭ wrote almost 4 years ago

It's just an example, dude. That's not relevant to the question.