...

View Full Version : C \ Python interface



-Fabez-
10-19-2008, 04:00 PM
I am trying to use some Python functions from C, using Dev C++ compiler. However, everything I try does not work, as it gives me a compiler and linker error, every time I try to compile the C code. Any input or help would be much appreciated. Thanks -Fabez-

shyam
10-19-2008, 04:14 PM
well, you could start by posting what compiler and linker errors you are getting...are the forum members supposed to read the crystal ball?

-Fabez-
10-19-2008, 04:27 PM
well, you could start by posting what compiler and linker errors you are getting...are the forum members supposed to read the crystal ball?

No but some people are actually capable of posting generic solutions and help, instead of criticizing others because they feel like it. However the point is also valid. The code I am trying to compile is.


#include "Python.h"
#include <stdio.h>
int main(){
Py_Initialize();
PyRun_SimpleString("Test=[1,2,3,4]");
Py_Finalize();
}

The errors I get are


[Linker error] undefined reference to `_imp__Py_Initialize'
[Linker error] undefined reference to `_imp__PyRun_SimpleStringFlags'
[Linker error] undefined reference to `_imp__Py_Finalize'
ld returned 1 exit status

oesxyl
10-19-2008, 04:41 PM
No but some people are actually capable of posting generic solutions and help, instead of criticizing others because they feel like it. However the point is also valid.
what generic solution have in mind for this kind of problem? People don't try to make you feel bad, just try to help you, that's all.


The code I am trying to compile is.


#include "Python.h"
#include <stdio.h>
int main(){
Py_Initialize();
PyRun_SimpleString("Test=[1,2,3,4]");
Py_Finalize();
}

The errors I get are


[Linker error] undefined reference to `_imp__Py_Initialize'
[Linker error] undefined reference to `_imp__PyRun_SimpleStringFlags'
[Linker error] undefined reference to `_imp__Py_Finalize'
ld returned 1 exit status
you forget to link python library to your executable.

best regards

-Fabez-
10-19-2008, 04:49 PM
I understand that, sorry for jumping to conclusions, how would l link to the Python library in Dev C++ ? The include and lib directories of Python are set as paths in the include and lib compiler options.

oesxyl
10-19-2008, 05:00 PM
I understand that, sorry for jumping to conclusions, how would l link to the Python library in Dev C++ ? The include and lib directories of Python are set as paths in the include and lib compiler options.
I have no idea, :) I don't even know what is Dev C++, :)
any compiler have a option to link explicit a library so this must have too.Try to look in his documentation.

I'm sorry, maybe shyam or somebody else know.

I search on the net and seems that this Dev C++ is a IDE. If it use gcc as compiler as it say here:

http://www.bloodshed.net/devcpp.html

you can use -lxxxx where xxxx is the python library( for a static library)
the switch is lower L, :)
best regards

-Fabez-
10-19-2008, 06:30 PM
Thanks a lot :D Where would I use -lXXXX ?

oesxyl
10-19-2008, 06:46 PM
Thanks a lot :D Where would I use -lXXXX ?
as far I read you must have a Makefile somewhere. if you post content it I try to see where it must be.

best regards

-Fabez-
10-19-2008, 07:11 PM
I dont think I have a makefile :( All I can find is my C code file.

oesxyl
10-19-2008, 07:27 PM
I dont think I have a makefile :( All I can find is my C code file.
I find this:
http://www.bloodshed.net/dev/doc/index.html

is a pdf about configuring Dev c++ to compile arm:

http://www.bloodshed.net/dev/SetDevCPPArm.pdf

at page 7 you have the picture of the linker tab, probably in menu Project -> Compiler
check the box "Add this command to the linker command" and in the textbox under it
a -lxxxx.

I hope it work this way.

If don't work you can try do in a terminal something like this:


gcc -g -W -Wall -Ipath-to-include-for-python -o main.o -c main.c
gcc -g -W -Wall -o mai.exe main.o -lxxx

this could work until you find how to do, :)

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum