1

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 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

"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.

1 Comment

I tried do your suggestion and get new errors: -unresolved external symbol __imp__Py_SetProgramName -unresolved external symbol __imp__Py_Initialize -unresolved external symbol __imp__Py_DecodeLocale in error list in File all of above error file is source.obj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.