graphitemaster / incbin

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

MSVC tool doesn't work #57

Open Makogan opened 2 years ago

Makogan commented 2 years ago

I compiled the incbin.c file and made an executable if I run it with help I get:

 ./a.exe phong_lighting.glsl  -I../../Src/Engine/EmbeddedShaders/ -o ../../buildvs/data.c  -help
C:\Users\Makogan\Documents\neverengine\libraries\incbin\a.exe [-help] [-Ipath...] | <sourcefiles> | [-o output] | [-p prefix]
   -o         - output file [default is "data.c"]
   -p         - specify a prefix for symbol names (default is "g")
   -S<style>  - specify a style for symbol generation (default is "camelcase")
   -I<path>   - specify an include path for the tool to use
   -help      - this
example:
   C:\Users\Makogan\Documents\neverengine\libraries\incbin\a.exe source.c other_source.cpp -o file.c
styles (for -S):
   camelcase
   snakecase

If I try to run it normally (without the help flag) this is the data.c file that gets generated:

  /* File automatically generated by incbin */
#include "incbin.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

No errors or warnings are thrown by the tool.

I am on windows 10

graphitemaster commented 2 years ago

You need to list the source files which use INCBIN you want preprocessed by this tool, you don't list the data files, those are read from the INCBIN macro in the source file which are found via -I. So for instance you'd have:

// source.c
INCBIN(data, "phong_lighting.glsl");

Then you'd run the tool with ./incbin.exe source.c -I../../Src/Engine/EmbeddedShaders/ -o ../../buildvs/data.c Which would emit a data.c file containing the phong shader source code as a byte array named data, now in source.c you can use data to refer to that embedded GLSL.

If you have multiple source files which use INCBIN you'd specify them all on the command line here.

ctalech commented 2 years ago

Ah I see, I was confused, thank you!

darealshinji commented 1 week ago

I was confused too. I think the description of how to use it should be clearer. I didn't understand that source.c was suppossed to be the source file that contains the INCBIN macros.

Maybe you should add a little counter so it's easier to understand that nothing was found?

diff --git a/incbin.c b/incbin.c
index fd1e72b..ca6abe4 100644
--- a/incbin.c
+++ b/incbin.c
@@ -104,7 +104,7 @@ static const char *styled(int style, int ident) {
 }

 int main(int argc, char **argv) {
-    int ret = 0, i, paths, files = 0, style = kCamel;
+    int ret = 0, i, paths, files = 0, style = kCamel, written = 0;
     char outfile[FILENAME_MAX] = "data.c";
     char search_paths[SEARCH_PATHS_MAX][PATH_MAX];
     char prefix[FILENAME_MAX] = "g";
@@ -263,6 +263,7 @@ usage:
                     fprintf(out, i != size - 1 ? "0x%02X, " : "0x%02X", data[i]);
                     count++;
                 }
+                written++;
                 free(data);
                 fclose(f);
             }
@@ -282,6 +283,7 @@ end:
         fprintf(out, "#endif\n");
         fclose(out);
         printf("generated `%s'\n", outfile);
+        printf("number of files included: %d\n", written);
         return 0;
     }