I have some code that currently uses GNU ld to link binary blobs into
the executable as follows:
ld -r -b binary -o xxx.o xxx
I can then link xxx.o into the final executable and access the data via
symbols _binary_xxx_start and _binary_xxx_end.
I'm now trying to get this to compile on OS X. Looking at the OS X ld
man page, I see the following option:
-sectcreate segname sectname file
The section sectname in the segment segname is created
from the contents of file file. The combination of
segname and sectname must be unique D there cannot
already be a section (segname,sectname) from any other
input.
Is this what I need? Can anyone offer any more information about it,
i.e. what should I use as segname and sectname and does it create
symbols like _binary_xxx_[start|end]?
Or, can anyone suggest an alternative way to do this? I believe that
the "Apple way" to do this sort of thing is using "resource forks" (?),
and I'd be interested to hear about that sort of thing, but my main
concern is to have as little that's platfrom-specific as possible in the
code.
Thanks,
Phil.
The *current* "Apple way" to do this sort of thing is to use an
application bundle and just include your blob as a data file therein.
Resource forks are strongly discouraged for new development, and have
been for years. But if you're writing a "real" Mac application today,
the overwhelming odds are that your distributable is going to be a
package - a folder that conforms to a specific structure and naming
convention and is treated by the GUI as an atomic file in most
situations that the user sees. For your code, though, it's just a
directory with the contents in predictable locations.
--
"Harry?" Ron's voice was a mere whisper. "Do you smell something ... burning?"
- Harry Potter and the Odor of the Phoenix
Thanks Gregory. Actually I'm not really "writing a real Mac
application" as you put it, but just trying to port some fairly simple
command-line code which, apart from this issue, seems to have no
problems with OS X. I'm considering embedding these blobs as string
literals in the C, with suitable escaping; it's ugly but I think it
would work.
Cheers, Phil.
> I'm considering embedding these blobs as string
> literals in the C, with suitable escaping; it's ugly but I think it
> would work.
I'm as unfamiliar with the linker magic as you are, but rather than do
the string route, check out the command-line tool xxd with the -i flag.
It might just be what you're looking for.
Avi