I want to embed python code in C++ console application vs2015. I followed the tutorial https://docs.python.org/3/extending/embedding.html, the very first example, 5.1 Very High Level Embedding. But when I built (in release mode) it shows an error: unresolved external symbol ___imp__py_initialize. I guess error occurred cause I don't Include some .lib or .obj files, so I include python.h and python.lib but I'm not sure. (I'm not good in English, so excuse me ...)
2 Answers
If you are sure that you have set the input and library directories correctly, then the cause of the linker problem might be that you are mixing codes of different bitnesses. Make sure that for example, you are not linking against the 64-bit versions of the Python libs in a 32-bit application.
Comments
"unresolved external symbol" is a linker error that means you forgot to link to a .lib file.
The Visual C++ project settings you need to embed Python are (for example Python 3.5):
- C/C++, General, Additional include directories: C:\Python35\include
- Linker, General, Additional library directories: C:\Python35\libs
You don't need to manually specify the .lib file because pyconfig.h auto-links to it when included.