Exclude binary ressource from compiling


is it possible, depending on a preprocessor directive, to exclude binary resource files from compiling? I have a different file for mac and windows, both added to the same projucer project. When I compile for win, the mac file should be excluded and for mac vice versa.


As an easy workaround, you could add both files and name them e.g. data_mac.xyz and data_win.xyz and then add the follwing to your code

namespace BinaryData // or whichever namespace you have chosen for your binary data
    const auto data_xyx = data_win_xyz;
    const auto data_xyzSize = data_win_xyzSize;
    const auto data_xyx = data_mac_xyz;
    const auto data_xyzSize = data_mac_xyzSize;

And then just use BinaryData::data_xyz in your code. This way both pieces of data will be compiled, but only one will be used so I guess the linker will be smart enough to remove the unneeded data from the final binary again

currently I have this exact method implemented and it works fine. But the goal is, to reduce the final binary file size, since each of these ressource files has a couple of MB of size.

As I said above, I would expect that the linker removes it from the final binary if it isn’t used anywhere. Or are you experiencing something different with your fully optimised release build binaries?

In the Projucer there is a switch: Include BinaryData in JuceHeader.h

Now you are free to include it yourself guarded by the platform macros as you wish…
Although thinking of it, it might still be in the object file from BinaryData.cpp supplied to the linker…

I follow PluginPenguin’s thought ,that the linker should strip the symbols, if that is selected in the settings (usually release)

Why not combine the technique you already have with something like this:

#include "Strings_MAC.h"
#include "Strings_WIN.h"

That is how we do platform specific binary data.

Since I had the problem on Windows (my main dev-machine), I expected the same behaviour on mac. But on Mac all unused File aren’t included in the final binary (with the same method PluginPenguin described). My compiler settings for both, win & mac are basically all default. Does anyone have an idea why it works on mac but doesn’t on win? (Both are release builds).

How do I get Projucer to pack the files into different resource files (Mac/Win)? On my side, all files are packed in the same binary data file.

compiler settings win:

compiler settings mac

Oh, yes a small detail that was left out there :joy:

I create those separate binary resources with the Projucer command line in a script, Projucer --help will give you the exact command needed, can’t remember off the top of my head what it is, but will be obvious from the list which is the binary builder option.