On Feb 9, 2010, at 3:39 PM, Marcel Dejean wrote: > objcopy can be used to turn binaries (e.g. images) into .o's . this > describes how to use it: > http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967
Wow, very cool. I like the approach someone took below in the comments to create the object files using the assembler. I even took that one step further and turned it into some easy-to-use macros in a common header file. Link: http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967#comment-348129 Code reproduced here for the lazy and for posterity: Original assembly example: .globl data_begin .data data_begin: .incbin "data.txt" .globl data_end data_end: My reply to that follows. Look at the end for how to use this. (Thank you for the initial code that got me started.) I turned the code into a macro, got rid of the global data_end and replaced it with data_len. You could go one big step forward and create a common header file containing the assembly and C macros. It could also contain a macro for C++. Then, just ifdef the macros based on the compiler flags. Then, you can just #include the same file, I think, in many places. // Common Include File: test.h #ifdef __ASSEMBLER__ .altmacro .macro binfile p q .globl \p&_begin \p&_begin: .incbin \q \p&_end: // Put a ".byte 0" here if you know your data is text // and you wish to use \p&_begin as a C string. It // doesn't hurt to leave it here even for binary data // since it is not counted in \p_&len .byte 0 .globl \p&_len \p&_len: .int (\p&_end - \p&_begin) .endm #else // Not __ASSEMBLER__ #ifdef __cplusplus extern "C" { #endif #define BIN_DATA(_NAME) \ extern char _NAME##_begin; \ extern int _NAME##_len #ifdef __cplusplus } #endif #endif // Assembly: test.S #include "test.h" .data binfile data "data.txt" binfile src "test.S" // C or C++: #include "test.h" BIN_DATA(data); BIN_DATA(src); _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

