Link to Python with MinGW

前端 未结 3 1482
谎友^
谎友^ 2020-12-01 13:22

I wan\'t want to create a cross-plattform programm that embedds the python interpreter, and compile it with MinGW. But the Python Binary distribution provides no libraries f

3条回答
  •  北海茫月
    2020-12-01 14:08

    EmbeddingPython.c

    #include 
    
    int main(int argc, char *argv[])
    {
        Py_SetProgramName((wchar_t *)argv[0]);  /* optional but recommended */
        Py_Initialize();
        PyRun_SimpleString("from time import time,ctime\n"
            "print('Today is', ctime(time()))\n");
        Py_Finalize();
        return 0;
    }
    

    and use gcc as following:

    gcc EmbeddingPython.c -I C:\Python34\include -LC:/Python34/libs -lpython34 -o a.exe
    

    and it works as we expected.

    D:\>a.exe
    Today is Fri Aug 29 15:14:04 2014
    

提交回复
热议问题