graphitemaster / incbin

Include binary files in C/C++
The Unlicense
938 stars 87 forks source link

Can you please produce a basic working example? #49

Closed PixelTwins closed 3 years ago

PixelTwins commented 3 years ago

I want to use the utility to modify an executable with resource changes. I have written this code:

#include <stdio.h>
#include "incbin.h"

int main(int argc, char** argv) {

    INCBIN(Code, "test.exe");

    unsigned char blip = gCodeData[0];
    printf("length %u", gCodeSize);
}

I have tried unsuccessfully to compile this code with Clang, Cygwin and MSys.

With Clang it throws these errors:

inc.o : error LNK2019: unresolved external symbol gCodeData referenced in function main
inc.o : error LNK2019: unresolved external symbol gCodeSize referenced in function main

With both Cygwin and MSys it throws these errors:

Warning: .type pseudo-op used outside of .def/.endef: ignored.
Error: junk at end of line, first unrecognized character is `g'
Error: file not found: test.exe
Warning: .type pseudo-op used outside of .def/.endef: ignored.
Error: junk at end of line, first unrecognized character is `g'
Warning: .type pseudo-op used outside of .def/.endef: ignored.
Error: junk at end of line, first unrecognized character is `g'

I get similar "junk at end of line" errors when I try to Make the "asserts.c" program packed with the repo.

Edit: I cannot withdraw an issue once submitted.

The program will not compile from within my NetBeans environment and this might be because of settings.

I have since successfully compiled and run this minimal working example from within MSys:

#include <stdio.h>
#include "incbin.h"

INCBIN(Code, "test.exe");

int main(int argc, char** argv) {
    printf("Length %u\n", gCodeSize);
}