# How to use includes correctly (incomplete types)

**URL:** <https://forum.juce.com/t/how-to-use-includes-correctly-incomplete-types/51331>\
**Category:** CMake\
**Created:** [May 7, 2022, 2:37pm UTC](https://forum.juce.com/t/how-to-use-includes-correctly-incomplete-types/51331 "2022-05-07T14:37:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MateoRidalgovic](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@MateoRidalgovic](https://forum.juce.com/u/MateoRidalgovic)\
**Post date:** [May 7, 2022, 2:37pm UTC](https://forum.juce.com/t/how-to-use-includes-correctly-incomplete-types/51331/1 "2022-05-07T14:37:23Z")

</div>

Hi there 😃

I have trouble when I try to include some JUCE headers in my own project. For example, if I want to use `MidiMessageSequence` class, I have to include `<juce_audio_basics/midi/juce_MidiMessage.h>` before `<juce_audio_basics/midi/juce_MidiMessageSequence.h>`, otherwise I get a compile error saying that `MidiMessage does not name a type`. And I have to include `<juce_core/juce_core.h>` before or I get incomplete type error.

And indeed, when I open the corresponding header files, there is no `#include` in them. How to fix this strange behavior ? This seems like JUCE is configured to use precompiled headers.

Here is a very simple project reproducing the issue :

> **Files**
>
> > **CMakeLists.txt**
> >
> > ```auto
> > project(ConsoleAppTemplate VERSION 0.1)
> > 
> > set (TargetName ${PROJECT_NAME})
> > 
> > juce_add_console_app(${TargetName} PRODUCT_NAME "Console App Example")
> > 
> > target_sources(${TargetName} PRIVATE Source/Main.cpp)
> > 
> > target_compile_definitions(${TargetName} PRIVATE
> > JUCE_WEB_BROWSER=0
> > JUCE_USE_CURL=0)
> > 
> > target_link_libraries(${TargetName} PRIVATE
> > juce::juce_recommended_config_flags
> > juce::juce_recommended_lto_flags
> > juce::juce_recommended_warning_flags
> > juce::juce_core
> > juce::juce_audio_basics)
> > 
> > ```
> 
> > **Source**
> >
> > > **Main.cpp**
> > >
> > > ```cpp
> > > #include <juce_core/juce_core.h> // <-- Needed
> > > #include <juce_audio_basics/midi/juce_MidiMessage.h> // <-- Needed too
> > > #include <juce_audio_basics/midi/juce_MidiMessageSequence.h>
> > > 
> > > int main()
> > > {
> > > auto test = juce::MidiMessageSequence();
> > > return 0;
> > > }
> > > 
> > > ```

---

<div class="post-metadata">

**Author:** ![Rincewind](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rincewind/32/10645_2.png) [@Rincewind](https://forum.juce.com/u/Rincewind)\
**Post date:** [May 7, 2022, 6:21pm UTC](https://forum.juce.com/t/how-to-use-includes-correctly-incomplete-types/51331/2 "2022-05-07T18:21:32Z")

</div>

Just include „JuceHeader.h“ that’s being generated by Projucer. If you want to be more cautious with includes, I think you can go with only including specific module headers, but you have to get their dependencies right.

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [May 7, 2022, 9:54pm UTC](https://forum.juce.com/t/how-to-use-includes-correctly-incomplete-types/51331/3 "2022-05-07T21:54:04Z")

</div>

To include a single module (ie not using juceHeader.h), you should `#include juce_audio_badics.h`

---

<div class="post-metadata">

**Author:** ![MateoRidalgovic](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@MateoRidalgovic](https://forum.juce.com/u/MateoRidalgovic)\
**Post date:** [May 8, 2022, 12:12pm UTC](https://forum.juce.com/t/how-to-use-includes-correctly-incomplete-types/51331/4 "2022-05-08T12:12:51Z")

</div>

Hello,

@Rincewind, I do not use the Projucer for my project but cmake 😉 Okay then, this behavior is not from a bad cmake configuration when building JUCE 🙂

@benvining If I include the whole `juce_audio_basics.h` only for one class, it will include a lot of unused code. In my humble opinion it is better to include only what you use. I mean the JUCE audio basics module is still pretty big, even if it is only one module. But I’ll go for this solution if it’s the only way to do things cleanly.

Thanks to both of you guys !  
Cheers

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [May 8, 2022, 12:25pm UTC](https://forum.juce.com/t/how-to-use-includes-correctly-incomplete-types/51331/5 "2022-05-08T12:25:23Z")

</div>

You’re absolutely right about that, but JUCE does not intend to support the use case of including individual headers. You would have to manually sort out the right order of includes yourself (and it may change in the future, too).
