470,855 Members | 1,158 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

importing embedded dynamic lib

I have a basic dynamic lib "noddy.so" which I want to
1- embed inside my executable
2- import by embedded python interpreter using an API call.

I have two questions:

1- what would be the recommended technique to embed a binary file inside
an executable?
My guess would be to add the binary "noddy.so" to the linking command,
but then
how do I get access to that chunk of code in my source file? My goal
would be to achieve something like

int* noddy_so = <binary here> ... but then how do I include the
binary code, or make the source code aware of it?

Using "#include" doesn't feel right, as this is a binary file, not
ASCII. And loading the file at run-time isn't right either, I need to
load it at compile time. And is "int*" the appropriate data type for
binary data?

2- Let's imagine that I managed to load "noddy.so" into my source code
somehow, and now have a pointer to it.
Any hints as to the correct python API call to import a dynamic lib
from a memory buffer? Could someone
tell me for example if the following makes sense for my purpose?

char *modulename="noddy", *filename="no_real_file";
PyObject *tmp;

/*Here try to translate the binary lib into a PyObject*/
tmp = Py_CompileString(noddy_so, filename, Py_file_input);
if (tmp == NULL)
error("Can't compile module [tmp]");

/*Import the "noddy" module*/
pmod = PyImport_ExecCodeModule(modulename, tmp);
if (pmod == NULL)
error("Can't load module [pmod]");

Jul 18 '05 #1
0 1060

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Rick Olson | last post: by
5 posts views Thread by John Benson | last post: by
5 posts views Thread by James | last post: by
3 posts views Thread by D.Stone | last post: by
1 post views Thread by jmc | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.