views:

61

answers:

3

My C application relies on some files to copy over. Will the files be contained in the executable and not as stand-alone files? Would it have to be linked statically? I am using Eclipse CDT if it matters.

A: 

No. The executable contains only the output from the compiler and linker. Any ancillary files your program requires must be packaged separately.

sizzzzlerz
A: 

Unless you do something special, no, the files will not be included in your executable. Is there a reason you can't distribute the text files with your application?

If you want to bake the files into your executable, you can bake them in constant strings:

const char myTextFileData[] = "the text of the file goes here";

Of course, you'll have to preprocess your text files into C source files (remembering to properly escape quotes, backslashes, newlines, and other control characters). Alternatively you can use a tool such as objcopy to convert the file data directly into an object file and then link that object file into your executable.

Adam Rosenfield
+3  A: 

There are several ways you can link file data into an executable. A platform like Windows allows you to link data into an executable as a "resource" and provides APIs to access those resources (this is how icons and other objects are bound into a Windows executable). This is probably the best way to do it if your platform supports it - support for it is built right into the IDEs.

At a lower level, you might be able to use the linker to directly link a file into an executable as an addressable object:

And finally, if you're dealing with a more primitive system like some embedded platforms, you can run your file through something that converts it into source for C array of bytes:

Michael Burr
+1 good survey of the options.
bstpierre