Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C \ Python interface

    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-
    I can code in, C++, C, Python, Html, Php, Javascript, Css, Visual Basic, MySql, ActionScript 2, ActionScript 3 and Mythbuster :)
    <Mythbusters> Am i missing an eyebrow ? </Mythbusters>

    Need a hand with coding or devoloping software ? Just ask ;) Or visit the Coding Group

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    well, you could start by posting what compiler and linker errors you are getting...are the forum members supposed to read the crystal ball?
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New Coder
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by shyam View Post
    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.

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

    Code:
      [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
    I can code in, C++, C, Python, Html, Php, Javascript, Css, Visual Basic, MySql, ActionScript 2, ActionScript 3 and Mythbuster :)
    <Mythbusters> Am i missing an eyebrow ? </Mythbusters>

    Need a hand with coding or devoloping software ? Just ask ;) Or visit the Coding Group

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by -Fabez- View Post
    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.

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

    Code:
      [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

  • #5
    New Coder
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 can code in, C++, C, Python, Html, Php, Javascript, Css, Visual Basic, MySql, ActionScript 2, ActionScript 3 and Mythbuster :)
    <Mythbusters> Am i missing an eyebrow ? </Mythbusters>

    Need a hand with coding or devoloping software ? Just ask ;) Or visit the Coding Group

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by -Fabez- View Post
    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.

    Edit: 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
    Last edited by oesxyl; 10-19-2008 at 05:06 PM.

  • #7
    New Coder
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot Where would I use -lXXXX ?
    I can code in, C++, C, Python, Html, Php, Javascript, Css, Visual Basic, MySql, ActionScript 2, ActionScript 3 and Mythbuster :)
    <Mythbusters> Am i missing an eyebrow ? </Mythbusters>

    Need a hand with coding or devoloping software ? Just ask ;) Or visit the Coding Group

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by -Fabez- View Post
    Thanks a lot 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

  • #9
    New Coder
    Join Date
    Oct 2008
    Location
    Earth
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont think I have a makefile All I can find is my C code file.
    I can code in, C++, C, Python, Html, Php, Javascript, Css, Visual Basic, MySql, ActionScript 2, ActionScript 3 and Mythbuster :)
    <Mythbusters> Am i missing an eyebrow ? </Mythbusters>

    Need a hand with coding or devoloping software ? Just ask ;) Or visit the Coding Group

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by -Fabez- View Post
    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:
    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •