Is there a Linux equivalent for Windows resource files?

I have a C library that I create as a shared object for Linux and a DLL for Windows with MinGW32. The API depends on several data files (statistical models) that I really would like to include in the SO / DLL so that the deployment is just one file.

It looks like I can achieve this for Windows with a โ€œresource fileโ€ compiled using windres , but then I need to write a bunch of resource handling code for Windows, and I still stick to the files on Linux.

Is there a way to achieve the same functionality on Linux?

Better yet, is there a portable solution?

+34
gcc cross-platform embedded-resource
Jan 04 '10 at 2:03
source share
2 answers

This is actually quite simple for Linux and other ELF systems: http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967

OS X has packages, so you just create your library as a framework and put the file in a package.

+31
Jan 4 '10 at 3:23
source share
โ€” -

Two possible solutions:

  • The Phong Vo sfio library , which is part of the AT & T technical support toolkit, is a great replacement for C stdio.h , and it will allow you to open files or blocks of memory with a single API. Thus, you can easily convert your existing files to C initialized data for inclusion in your DLL or SO file.

    This is a good cross-platform solution, but the punishment is that the learning curve for the start is pretty high. They do not allow you to easily understand how the material works, or to take one part of your toolbox and divide it into use independently of other parts. But the good news is that if you want to use your U / Win system to run Unix codes on Windows (all parts of the same toolkit), you can create DLLs and SOs using the same system.

  • For this problem, I often return to Lua ; I can store Lua data in external files or inside C as initialized data. This is great for distributing in just one .so file; I do this for my students.

    Again, the disadvantage is that you need to master and incorporate new technology.

In my work, I use Lua on AT & T materials for the following reasons:

  • Lua has a much smaller size and is designed to play well with others; with AST you really do accept your way of doing things.

  • The learning curve with Lua is much less steep; You can be productive very quickly.

  • Lua is easy to install and easy to get information about. AST has its own bizarre installation process that no one sees in the world; it is often difficult to make an installation; and harder to get information about it.

  • Using Lua has many other benefits, so the effort spent learning Lua and learning how to incorporate Lua into C codes is easy to amortize across multiple projects.

-one
Jan 04 '10 at 3:02
source share



All Articles