Issues with Binary Data

When compiling my project with an image I have as a Binary File I receive the following error:

error LNK2001: unresolved external symbol "char const * const BinaryData::Untitled_png" (?Untitled_png@BinaryData@@3PEBDEB)

I have exhausted all troubleshooting within my scope of knowledge, and from what i can find on these forums. I have tried a different image of a different size and recompiled and get exactly the same error which leads me to believe the issue is with my implementation of the class but I have no idea what the problem is

I have compiled a binary data file using the BinaryBuilder program supplied in the extras folder of Juce, which has been placed with my project files. I have then written an #include for the header file in the JuceHeader.h file.

After declaring in my editor header file as such:

const char* imageData = BinaryData::Untitled_png;
const int imageDatasize = BinaryData::Untitled_pngSize;

I have used two methods of implementation:

image= ImageCache::getFromMemory(imageData,imageDatasize);
g.drawImageAt(image, 0, 0);

image = ImageFileFormat::loadFrom(imageData, (size_t)imageDatasize);
myimage.setImage(image);

Both of which give the same error.

Can anyone help with this? Thanks

Did you add that source file to your Projucer project as a file to compile?

1 Like

To result in something resembling this?

image

Results in same error

Ok I have fixed it with your help here McMartin

When I open the project from projucer it overwrites my (handwritten) #include BinaryData.h call. When re-writing it will compile

So now I have a problem because the Projucer isn’t writing the include in JuceHeader.h even with this enabled:

Which ultimately is likely because of a prior problem I have: Projucer doesn’t compile at all for me, and never has - I get “JIT process stopped responding”. This happens on all versions of Juce and I have never bothered to fix it as I can work completely independently in Visual Studio.

Is there a workaround here? Why does the file need to be in projucer for my code to compile? Ideally I want to work in this framework without having to deal with Projucer at all.

You shouldn’t have to add anything. The declarations you put into your headers are rather confusing things than helping.
The data in BinaryData is automatically added, you find it in the section “JUCE Library Code”.
And it is included automatically in the “JuceHeader.h”
When you add source files, they are eventually duplicated.

Best to try again fresh without any addition

Right nevermind it’s because I hadn’t right clicked the file and declared them binary files

Either way, I don’t understand why I have to go through projucer for this. Surely this all should be able to work independently of projucer if you wanted it to

I know, people can only appreciate the Projucer, once they tried to setup a build for 4 different targets with shared code to create the libraries in the right format, so the various plugin hosts can see them.
It might be doable and not be too hard for applications, but to set all settings so it just works is not really trivial.

So instead of having several howto pages, how to set up in your IDE of choice, the Projucer just generates a project for you, that you can flesh out.

And in fairness, it is quite common to have a tool creating your build instructions, be it auto-conf, cmake, gradle, or whatever else… it will always be the wrong choice for the majority anyway…

1 Like

Fair enough, don’t really think about that at this scale - all the extra apps start to seem like roadblocks rather than helpful features

Just to clarify something, when in projucer both the Binary file header and cpp should be ticked as a binary resource? Or are both ticked as a binary resource? The manual doesn’t specifiy

Well this has broken for me again, I re-did the file and put it in the proper way and now the image doesn’t show, however I get no error.

Like I said, none of that is necessary. Just add the binary file to the projucer:

This is the generated code:

The BinaryData.cpp is built and linked by default, it should not be seen in the Source section.

Ah drag and drop image. Well I never

So the BinaryBuilder.exe isn’t needed here then. Must have been on some old forum posts

Edit: Cheers by the way