# I 'm having trouble understanding how BinaryData works in CMake

**URL:** <https://forum.juce.com/t/i-m-having-trouble-understanding-how-binarydata-works-in-cmake/61233>\
**Category:** Getting Started\
**Created:** [May 5, 2024, 9:28am UTC](https://forum.juce.com/t/i-m-having-trouble-understanding-how-binarydata-works-in-cmake/61233 "2024-05-05T09:28:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xyzuvw](https://avatars.discourse-cdn.com/v4/letter/x/f475e1/32.png) [@xyzuvw](https://forum.juce.com/u/xyzuvw)\
**Post date:** [May 5, 2024, 9:28am UTC](https://forum.juce.com/t/i-m-having-trouble-understanding-how-binarydata-works-in-cmake/61233/1 "2024-05-05T09:28:52Z")

</div>

Newbie here.  
Began to study JUCE since this January and I recently changed my IDE from VS to CLion.  
Problem I immediately noticed is that the BinaryData.h seems to work differently at least superficially comparing to previous Projucer-VisualStudio2022 experience. I’m also seeing the BinaryData.h underlined because it was missing.  
I was trying to open PNG file and draw it for the “background” but I got no luck understanding or seeing any examples how this thing should be done in CLion.

Thank you for reading. Hope I can address this issue soon.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 5, 2024, 9:31am UTC](https://forum.juce.com/t/i-m-having-trouble-understanding-how-binarydata-works-in-cmake/61233/2 "2024-05-05T09:31:23Z")

</div>

There are two things to do, one is to create the binary data:

```auto
juce_add_binary_data(
        MyProject_data
        SOURCES
        Logo-FF.png
        Logo-FF-text.png
)

```

And then link it to your target, e.g.:

```auto
target_link_libraries(MyProject
        PRIVATE
        MyProject_data
        foleys::foleys_gui_magic
        foleys::foleys_dsp_magic
        juce::juce_core
        juce::juce_audio_processors
        juce::juce_audio_devices
        juce::juce_audio_utils
        juce::juce_gui_basics
        juce::juce_gui_extra
        juce::juce_graphics
        juce::juce_cryptography
        juce::juce_recommended_config_flags
        juce::juce_recommended_lto_flags)

```

---

<div class="post-metadata">

**Author:** ![kerfuffle](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/kerfuffle/32/11805_2.png) [@kerfuffle](https://forum.juce.com/u/kerfuffle)\
**Post date:** [May 5, 2024, 9:32am UTC](https://forum.juce.com/t/i-m-having-trouble-understanding-how-binarydata-works-in-cmake/61233/3 "2024-05-05T09:32:04Z")

</div>

You need to add the following to your CMakeLists.txt:

```auto
juce_add_binary_data(BinaryData SOURCES
    Logo.png
    Font.ttf
)

```

and then link to it:

```auto
target_link_libraries(${PROJECT_NAME}
    PRIVATE
        BinaryData
        juce::juce_audio_utils
    // ... and so on ...
)

```

Run `cmake` again whenever you add new files to the BinaryData.

EDIT: Beaten to it by Daniel! 🙂

---

<div class="post-metadata">

**Author:** ![xyzuvw](https://avatars.discourse-cdn.com/v4/letter/x/f475e1/32.png) [@xyzuvw](https://forum.juce.com/u/xyzuvw)\
**Post date:** [May 5, 2024, 9:44am UTC](https://forum.juce.com/t/i-m-having-trouble-understanding-how-binarydata-works-in-cmake/61233/4 "2024-05-05T09:44:39Z")

</div>

Wow I regret hesitating posting questions here. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![xyzuvw](https://avatars.discourse-cdn.com/v4/letter/x/f475e1/32.png) [@xyzuvw](https://forum.juce.com/u/xyzuvw)\
**Post date:** [May 5, 2024, 9:47am UTC](https://forum.juce.com/t/i-m-having-trouble-understanding-how-binarydata-works-in-cmake/61233/5 "2024-05-05T09:47:41Z")

</div>

Managed to solved the problem after posting the question here. Thank you so much!
