Linking problem w. wxPython (core_wrap.o)

Vio wrote:

What part of my problem are you referring to? The linking problem or embedding wxPy or something else?

embedding wxPy.

-Chris

Never did a wiki before, but sure, why not. Well, it's no big deal, all I did is:

1) read the generic "embedding python" docs - available at www.python.org -
and read/run the embedding example available in the python sources

2) took the "minimal" wxWidgets code sample and added the lines from the
generic embedding example (namely #include "Python.h" and Py_Initialize():wink:

NOTE:I haven't tested step 3 yet, as I got stopped by these linking problems previously mentionned. But things should go like this:

3.1) Include the wxPython headers
#include "wx/wxPython/wxPython.h"

3.2) The SWIG bindings for Python come in 2 parts: a "cpp" part, and a "py" part.
First initializing the "cpp" part:

extern "C" {
extern void init_myexample(); // some other Python extension
extern void init_core(); // <-- the wxPython wrapper... this call name may be wrong, //I haven't tested it yet, but you get the idea
//... init the other wrappers part of wxPython here
}
//and then somewhere after Py_Initialize() call it! Next step.

3.3) Now init the python part. Just for testing purposes, and out of pure laziness,
I do that by calling the "About" menu command (see "minimal" code).

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
  /* --PYTHON-START--
  SWIG-Python extension consist of 2 parts: a 'cxx' part and a 'py' part
  running the 2 parts is equivalent to the py command: 'import example'
  */

  // 1. import the compiled 'cxx' part (already compiled+linked)
  init_example(); // import my Python extension

  PyRun_SimpleString("print '\n\n\ndir()1>',dir(),'<\n\n'"); //test
  init_core(); // import wxPython extension - again, I'll have to check if "core" is the right call here, and if other wxPy libraries need to be called as well
  PyRun_SimpleString("print '\n\n\ndir()2>',dir(),'<\n\n'"); //if now "dir()" shows some wxPy objects, we've half succeeded

  //2.1 join strings and execute Python code

ยทยทยท

-------------------
NOTE: since g++ compiler on Win32 doesn't accept multiline literals, I simply cut
the SWIG-generated python file into single-line wxStrings (with a simple python script
run manually). The next function simply joins
those together, then passes those python sources to PyRun_SimpleString().
My goal is to have the python part (of SWIG-generated code) also embedded, so no
dependancies outside this huge chunk of executable code. Well, that's the goal...
Also, I optimize for laziness... sorry for my cheezy solution
-------------------
  assemble_py_file_and_execute( get_EXAMPLE_PY_H() );
  assemble_py_file_and_execute( get_RUNME_PY_H() );

  PyRun_SimpleString("print '\n\n\ndir()3>',dir(),'<\n\n'"); //final test
  // --PYTHON-END--

}

4) And here you have it. From here on you invoke wxPython through PyRun_SimpleString().
I guess that's my unpublished wiki.
Hope this helps (... and I hope I'll manage to go beyond step 3 :slight_smile:
Vio