graphitemaster / incbin

Include binary files in C/C++
The Unlicense
941 stars 90 forks source link

the `const` keyword prohibits compilation #9

Closed IngwiePhoenix closed 9 years ago

IngwiePhoenix commented 9 years ago

I have almost completely ported my project to use incbin. However, I am struggling with C++.

I created a file called scripts.rc which simply contains:

#include "incbin.h"

INCBIN(Configurable, "lib/configurable.os");
INCBIN(libIceTea, "lib/IceTea.os");
INCBIN(main, "lib/main.os");

And within my main code:

// Embed
#include "incbin.h"
#undef INCBIN
#define INCBIN(NAME, PATH) INCBIN_EXTERN(NAME)
#include "scripts.rc"

That, on it's own, works. Its a cheaty hack so that I can use the three step build on all platforms. That is:

gcc incbin/incbin.c -o out/incbin
out/incbin src/scripts.rc -o src/scripts.cpp
g++ src/*.cpp -o icetea

However, the const keyword is giving me issues. The ...Data[] symbols get all mangled with the name, and it turns out that this is why.

For now, I have to find a way to work this out...

IngwiePhoenix commented 9 years ago

Turns out the const keyword infront of the actual data causes issues on all systems. There is no issue with the ...End and ...Size symbols, but only with the ...Data symbols. I have made a fork and removed the const keyword there.

graphitemaster commented 9 years ago

extern "C" is what the script needs

graphitemaster commented 9 years ago

You're using the tool wrong anyways. You're not suppose to include a header file that uses INCBIN. You're suppose to use INCBIN in source files only and then reference data externally with INCBIN_EXTERN. This is documented.

IngwiePhoenix commented 9 years ago

I've used the header simply due to keeping things organized. It works out since that is only included at one place. I might change it later, but for now that simply seems to reduce typing duplicated things. ^^