g++ with python.h, how to compile

后端 未结 2 1204
梦谈多话
梦谈多话 2021-02-06 02:33

I compile one test code with g++ without any issue.

#include \"Python.h\"  

int main(int argc, char** argv)  
{  
    Py         


        
相关标签:
2条回答
  • 2021-02-06 03:15

    This is a bug in Python: https://bugs.python.org/issue1045893

    If you include first Python.h, the compiler won't complain but GNU libc's /usr/include/features.h will override it anyway when _GNU_SOURCE is defined:

    # undef _POSIX_C_SOURCE # define _POSIX_C_SOURCE 200809L # undef _XOPEN_SOURCE # define _XOPEN_SOURCE 700

    0 讨论(0)
  • 2021-02-06 03:18

    Take a look at Lucas's comment for the answer:

    "To get rid of the _POSIX_C_SOURCE warning, make sure to include Python.h before all other header files."

    I had the same problem. I use Boost Python, so for me I moved the include of boost/python.hpp to the first line in my .cpp file.

    (Lukas, post your comment as an answer so the person who asked can mark it as the right answer, and the question won't remain 'unanswered' in StackOverflow.)

    0 讨论(0)
提交回复
热议问题