0

Possible Duplicate:
How to Embed/Link binary data into a C++ DLL

I need a commandline tool which could embed my binary file(s) into some (C way linkable) .obj file - this binary data should be under some given symbols to reach to it from c code

Is there such tool? (I am especially interested in windows platform, coff and omf formats )

Community
  • 1
  • 1
grunge fightr
  • 1,360
  • 2
  • 19
  • 38
  • 1
    Usually the easiest way is to convert the binary file into C source code, and feed that through the compiler to the linker. Not sure if that's acceptable here. – MSalters Oct 21 '12 at 12:30
  • The more I look around on SO, this questions is beginning to look like a duplicate of either [this](http://stackoverflow.com/q/2740164/21567) or [that](http://stackoverflow.com/q/4158900/21567) one. You might want refine your question and/or get more specific. – Christian.K Oct 21 '12 at 12:54
  • It is not a duplicate I am asking about tool for static modules (obj), gosh – grunge fightr Oct 24 '12 at 10:55

2 Answers2

1

If you are using gcc. You can use the linker to do just that using something like:

ld -r -b binary -o foo.o foo.txt

Take a look here

dvhh
  • 4,724
  • 27
  • 33
doron
  • 27,972
  • 12
  • 65
  • 103
1

If a windows-only solution is sufficient, i.e. portability is not required, you could also use binary resources and the "standard" resource compiler, tool, and formats.

Resources don't have to be just icons, cursors, dialogs, etc. but can also be arbitrary data. Here is an example. Or this stackoverflow answer.

I do not know what exactly you are trying to achieve here, but if you search stackoverflow or google for "embed binary as resource" you'll find a couple of examples.

Community
  • 1
  • 1
Christian.K
  • 47,778
  • 10
  • 99
  • 143
  • windows resources are unhandy, I need commandline tool to put binary under some symbol name in linkers obj - want to find a tool – grunge fightr Oct 21 '12 at 13:03
  • It wouldn't be too complicated to write a reusable script that first creates a wrapper resource script for your binary, second calls rc.exe to create the .res file an third calls link.exe to create the final .dll/.exe that contains your binary. The benefit of resources are, that they are easily extractable. Either by the application they are contained in itself, or by some stand alone tool. YMMV, of course. – Christian.K Oct 21 '12 at 15:12