search

Home  >  Q&A  >  body text

python3.5 - c++ calls python36

First you need to configure the environment, create a win32 console program, and then configure the project.
Project–>Properties–>vc++ directory–>Include directory Add the include directory in the python installation directory
Project–>Properties–>vc++ directory–>Library directory Add the libs directory in the python installation directory
Linker–>Input–>Additional Dependencies Add python36.lib

Note that if the C++ project uses the debug version, you need to copy the python36.lib file under the libs folder in the python installation directory and change the name to python36_d.lib

Follow the above steps to run the code, and an error will be reported. A lot of symbols cannot be parsed

Find the solution after Baidu:

Modify pyconfig.h

#ifdef _DEBUG 
# define Py_DEBUG 
#endif 

改为

#ifdef _DEBUG 
//# define Py_DEBUG 
#endif 
# ifdef _DEBUG 
# pragma comment(lib,"python27_d.lib") 
# else 
# pragma comment(lib,"python27.lib") 
# endif /* _DEBUG */ 

改为

# ifdef _DEBUG 
# pragma comment(lib,"python27.lib") 
# else 
# pragma comment(lib,"python27.lib") 
# endif /* _DEBUG */ 

Modify object.h

#if defined(Py_DEBUG) && !defined(Py_TRACE_REFS) 
#define Py_TRACE_REFS 
#endif 

改为

#if defined(Py_DEBUG) && !defined(Py_TRACE_REFS) 
// #define Py_TRACE_REFS 
#endif

I still get the same error after running it. I have no choice but to ask God.

世界只因有你世界只因有你2738 days ago573

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-05-16 13:29:19

    Let’s use py2, py2 can be used, but I still haven’t solved the above problems with py3

    reply
    0
  • Cancelreply