0

I am trying to embed python in a Visual C++ application using visual studio 2017.

I correctly included the header files path and the lib path from my Python 3.7.0 installation.

I can include the Python.h and pylifecycle.h files but get an error when I try to run the program. My code and error is below.

// TestPythonEmbedding.cpp : Defines the entry point for the console     application.
//

#include "Python.h"
#include "pylifecycle.h"
#include "stdafx.h"


int main()
{
    PyObject* myPointer;

    Py_Initialize();
    return 0;
}

Here are the errors I get when I try to build the solution.

testpythonembedding.cpp(11): error C2065: 'PyObject': undeclared identifier

testpythonembedding.cpp(11): error C2065: 'myPointer': undeclared identifier

testpythonembedding.cpp(13): error C3861: 'Py_Initialize': identifier not found

1>Done building project "TestPythonEmbedding.vcxproj" -- FAILED.

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Strangely enough Visual studio gives information about Pyobject* and highlights it as if it is identified. I included an image of that.

image

Community
  • 1
  • 1
Danial Esaid
  • 51
  • 1
  • 4
  • 2
    `stdafx.h` must always be included first. If you're not sure how precompiled headers work it's generally better to turn them off as you're likely getting no benefit. https://stackoverflow.com/a/2976046/920069 – Retired Ninja Sep 10 '18 at 00:59
  • https://stackoverflow.com/questions/20281372/how-to-deal-with-the-pyobject-from-c-in-python – Santosh Dhanawade Sep 10 '18 at 07:15

0 Answers0