I have a C++ program foobar
which starts with main()
and then the flow of control goes through a first part, then the second part of the program. If I change main
to foobar_main
, I can then compile the whole program and a SWIG Python wrapper to a shared library foobar.so
, and import this to Python, call foobar_main
from within Python and everything works fine.
The second part communicates with the first one by some respectable C++ constructs. Specifically: the first part creates some single objects of some classes, and the second part uses class static methods to get those objects.
Now I want to run only the first part from main()
and the second part from Python. That is, I want to start the C++ program foobar
and then after the first part is finished, run a Python script (programmatically from within C++) that continues with the second part.
To do this, I:
- compile the second part and a SWIG wrapper to
foobar2.so
- replace the second part of C++ code with
system("python foobar2.py")
- compile the modified C++ program to
foobar1.so
and load tofoobar
- write the script
foobar2.py
which importsfoobar1
andfoobar2
and then equivalent to the second part
Then I attempt to run foobar
. It does not work, because it appears, that the routines in the second part complain that certain steps which should have been done in the first part, are not done.
This is embarasing but obviously I have some deep flaws here in my understanding of how computers work :) Can somebody clue me in what I am missing, including possibly simplifying the above process?