importing embedded dynamic lib

Discussion in 'Python' started by Vio, Jun 9, 2004.

  1. Vio

    Vio Guest

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

    Regards,
    Vio
    Vio, Jun 9, 2004
    #1
    1. Advertising

  2. Vio

    Miki Tebeka Guest

    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.
    --
    -------------------------------------------------------------------------
    Miki Tebeka <>
    The only difference between children and adults is the price of the toys.
    Miki Tebeka, Jun 10, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Yong
    Replies:
    0
    Views:
    527
    James Yong
    Sep 12, 2005
  2. Replies:
    1
    Views:
    346
    David Fraser
    Nov 26, 2004
  3. plb
    Replies:
    2
    Views:
    314
  4. Praetorian

    Need odbc32.lib odbccp32.lib

    Praetorian, Apr 20, 2006, in forum: C++
    Replies:
    1
    Views:
    1,348
    mlimber
    Apr 20, 2006
  5. Harold
    Replies:
    3
    Views:
    242
    Harold
    Jan 12, 2013
Loading...

Share This Page