importing embedded dynamic lib

V

Vio

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]");
 
M

Miki Tebeka

Hello Vio,
I have a basic dynamic lib "noddy.so" which I want to
1- embed inside my executable
Why? What is the reason you can have multiple files?
2- import by embedded python interpreter using an API call.

1- what would be the recommended technique to embed a binary file inside
an executable?
Have a look at what Python Installer does (or NSIS installer).
IMO the OS will need a "real" file so what you'll have to do is extract
it at runtime and then load it.
2- Let's imagine that I managed to load "noddy.so" into my source code
somehow, and now have a pointer to it.
Again. I'd extract it to a temporary file and load it. This way you can
use the regular `import'.

HTH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top