LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-25-2006, 10:30 AM   #1
Sir Valeq
LQ Newbie
 
Registered: Dec 2005
Posts: 3

Rep: Reputation: 0
Unhappy 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.
 
Old 01-27-2006, 09:54 AM   #2
YetAnotherDave
Member
 
Registered: Feb 2005
Posts: 95

Rep: Reputation: 17
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Processing Conflict: python-devel conflicts python< 2.3.4-13.1 guarriman Fedora 2 04-23-2009 07:02 PM
python problem Cyber Maid Linux - Software 4 10-16-2005 12:00 AM
python problem tehnick Linux - Newbie 1 03-26-2005 08:27 AM
python problem kenji Linux - Software 1 03-25-2005 12:44 PM
python problem rblau Linux - Software 0 03-03-2004 10:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration