LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Python/C++ problem (https://www.linuxquestions.org/questions/programming-9/python-c-problem-407838/)

Sir Valeq 01-25-2006 10:30 AM

Python/C++ problem
 
Hi!

I'm writing a PAM module that should call Python functions (from a script) to do the security stuff. So I have to call Python functions from the *.so file and, moreover, provide the script with the ability to call C++ functions defined in the same *.so module (like functions for getting the username with pam_get_user()).
So now, my problems:

1. when i import the python module with PyImport_Import() (just like in the Python/C API Reference from python.org) i get the following error:
'import site failed'
There is no 'import site' in my script, only a simple function. I found a solution in the newsgroups, telling me to create an empty site.py and a lib-dynload directory and set $PYTHONPATH to those. I did that. It helped, there is no 'import site failed', but...
... now i can't import any other python modules in the script, and I need to import the 'dl' module in order to load the *.so and call the C++ functions.
Any help?

2. I have problems with making the C++ functions in a test *.so file callable for a Python script. I write the C++ source, compile it with -shared to get the *.so, but then, when in Python shell I import the *.so (with dl.open()) and try to call a functions from it, it says that there is no such function defined in the module.
Does anyone have any examples on calling C++ functions from Python and making such *.so files?

If you need me to write more on my problems or provide the code I'm using, just tell. :)
It's kinda urgent so I'll be gratefull for any help. :)

YetAnotherDave 01-27-2006 09:54 AM

2. I have problems with making the C++ functions in a test *.so file callable for a Python script. I write the C++ source, compile it with -shared to get the *.so, but then, when in Python shell I import the *.so (with dl.open()) and try to call a functions from it, it says that there is no such function defined in the module.
Does anyone have any examples on calling C++ functions from Python and making such *.so files?
If you're not already using swig for calling c++ from python, try it out. I have used it in the past and it makes calling c++ from python a piece of cake. If you have trouble getting swig to work, let me know and I can help out.

- Dave


All times are GMT -5. The time now is 02:41 PM.