1

I want to compile a .c file containing a Header Python.h using minGW on Windows 10. My Goal is to embedd some pythoncode in C an this is just a little test for the compiling.
My sourcefile looks as follows:

#include <stdio.h>
#include <C:\Python27\include\Python.h>

int main() 
{
    printf("Hello World from C");

    Py_Initialize();

    PyRun_SimpleString("print('Hello World from Python!!!')");

    Py_Finalize();


    return 0; 
}


My makefile looks as follows:

all: HelloWorld.c
    gcc -Wall -I C:\Python27\include -L C:\Python27\libs  -o HelloWorld.exe HelloWorld.c -lpython27


So if I compile my source Code with this makefile I get the following error:

gcc -Wall -I C:\Python27\include -L C:\Python27\libs  -o HelloWorld.exe HelloWorld.c -lpython27
C:\Users\ga96dux\AppData\Local\Temp\ccUQs2pM.o:HelloWorld.c:(.text+0x1b): undefined reference to `_imp__Py_Initialize'
C:\Users\ga96dux\AppData\Local\Temp\ccUQs2pM.o:HelloWorld.c:(.text+0x31): undefined reference to `_imp__PyRun_SimpleStringFlags'
C:\Users\ga96dux\AppData\Local\Temp\ccUQs2pM.o:HelloWorld.c:(.text+0x38): undefined reference to `_imp__Py_Finalize'
collect2.exe: error: ld returned 1 exit status
make: *** [all] Error 1


I´ve tried everything I could find in the Internet but it doesn't work, is there anything wrong with the makefile, are there any suggestions how to solve this Problem? Thank you very much!

Felix.A
  • 11
  • 2

0 Answers0