Hello,
I'm trying to include the Python interpreter in my C program to execute some Python code:
/* main.c */ #include <python2.5/Python.h> int main ( int argc, char* argv [] ) { Py_Initialize (); PyRun_SimpleString ( "print ( 'Hello world!' )" ); Py_Finalize (); return ( 0 ); }
I'm having trouble compiling and linking the C program. If I've understood correctly, I need to link libpython25.so library to my program to make it work. I've tried compiling it with these parameters
gcc -Wall -llibpython25 -oMyPythonTest main.c
but I get this error:
ld: cannot find -llibpython25
A few things here. You don't need to specify "lib" so using "-lpython25" is fine.
If you really need to use a .so then you will need to specify "-use-dynld" on the compile line like so:
Check the AmigaOS 4.1 SDK.pdf in the SDK root for more info.
Thanks! I managed to compile and link the program but not without issues.
The linker notified that libpython25.so needs these libraries also:
So I tried linking all those libraries to my program:
The linker complained that it cannot find libz.so and libz.so.1 libraries. Only after copying libz.so from SOBJS: to SDK:local/newlib/lib/ solved the problem.
Good it's compiling now at least. That's strange it can't find it in SOBJ: path. The SDK guide mentions four search paths. As useful as the so objects are I think they complicate the program for users. The Amiga has always had a major problem with no package manager. I installed a program that needed all these objects that weren't supplied and after tracking a few down, I found it still wouldn't load and I had to hack the files in my SOBJ: for it to work. Nice idea but I think they needed more work when implementing the objects.
Have you tried getting out Snoopy to track the loading fails?
If there was a static python lib it would be easier. :-)
On my system libz.so and libz.so.1 are links while the objects that the linker had no problem with are actual files. When libz.so was copied, the resolved link (actual file) was probably copied. Possibly there is a problem with links??
X1000 - OS 4.1FE
No I haven't.
I have these file links in the SDK:local/newlib/lib/ directory now
and these files
I have the same and they all point to SOBJS:
I have most except I only have one libz.so named libz.so.1.2.3. I have all the rest.
Also, the ".a" lib files won't matter here as you are using ".so" objects. Though it can be done, with some work, they don't recommend linking both ".a" and ".so" types of libs into a binary.