Help needed Using BinaryData with cmake (JUCE 6)

I’m trying to use Binary Data with cmake and JUCE 6.

I’ve done the following thing:

1.- Put all images in a folder called Images

2.- Created this cmakelist.txt doc in that folder:

juce_add_binary_data(WanalogBinaryData SOURCES

3.- I added the
line in the root CMakeLists.txt document, so the Images folder gets included

4.- I’ve also added the WanalogBinaryData to the linking phase like this:

target_link_libraries(WanalogAudioPlugin PRIVATE
        WanalogBinaryData           # If we'd created a binary data target, we'd link to it here

I see that the Binary data .o file is being compiled properly.

My question is… How can I now access this bynary data on source code?

BinaryData::whatever does not work any more.

1 Like

If you’re using a JuceHeader, then the binary data header should be automatically included in there. If you’ve opted to avoid the JuceHeader (recommended), you can just #include BinaryData.h in the places that you need it.

Let me know if that doesn’t work, and I’ll try to find out what’s going wrong.

1 Like

Yes, it worked!
The IDE was marking the BinaryData in red as unresolved symbol, which was confusing me but when I compile, it works, so I guess it’s the IDE not being able to resolve symbols.

Glad you got it working! This might be because the BinaryData files are generated during the build, so the IDE may not be able to find them until the build has been run once (and even then, some IDEs might need a bit of a nudge to re-index the binary directory…)


Quick follow up question: What is the syntax for using the juce_add_binary_data in a cmakelists.txt file in another folder? Cmake is saying it does not recognize the function, do I need to add something from the juce library to use that function?

juce_add_binary_data will only work after JUCE has been included, normally with add_subdirectory(JUCE).