0

I'm using visual studio 2019 and python 3.8. I'm trying to make a C extension for Python, and I was trying to figure things out and found this tutorial https://learn.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio?view=vs-2019

I followed all instructions but visual studio gives me multiple errors, like Python development files are not installed. Please add the development files, or repair your existing installation. calcmodule C:\Users\Heno\Desktop\nics stuff\tictactoe\calcmodule\calcmodule\calcmodule.vcxproj

Also I need to use nullptr but visual studio gives me Error (active) E0020 identifier "nullptr" is undefined calcmodule C:\Users\Heno\Desktop\nics stuff\tictactoe\calcmodule\calcmodule\calcmodule.c

Here is my code (i couldn't get anything working so i guess i have to fix a lot of things. if you have tips for me please tell):

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <Windows.h>
#include <assert.h>
#include <stdlib.h>

//get user input getline(cin, input)
static PyObject* calc_hello(PyObject* self, PyObject* args)
{
    //PyObject *obj_a = NULL;
    char inpMsg;
    char retMsg[] = "Hello back!";

    goto try;
    try :
        assert(!PyErr_Occurred());
    //use assert?

    if (!PyArg_ParseTuple(args, "s", &inpMsg))
    {
        PyErr_SetString(PyExc_ValueError, "couldn't parse tuple.");
        goto except;
    }
    goto finally;
except:
    //Py_XDECREF(inpMsg);
    assert(PyErr_Occurred());
    //inpMsg = NULL;
    //retMsg = NULL;
    finally:
    //Py_XDECREF(objects);
    //Py_DECREF(args);
    //return retVal;
    if (retMsg != nullptr)
    {
        return Py_BuildValue("s", retMsg);
    }
}

static PyMethodDef calc_methods[] = {
  {"hello", (PyCFunction)calc_hello, METH_VARARGS, "hello world func"},
  {nullptr, nullptr, 0, nullptr}
};

static struct PyModuleDef calcmodule =
{
    PyModuleDef_HEAD_INIT,
    "calcmodule",
    "all calculations for tictactoe",
    -1,
    calc_methods
};

PyMODINIT_FUNC PyInit_calc(void)
{
    return PyModule_Create(&calcmodule);
}```

Thank you very much for your help!
Romero
  • 1
  • 1
  • `nullptr` is c++ but not c. Are you compiling it as c++? – DavidW May 06 '20 at 12:05
  • ok that problem is solved (thanks :D), but it's still giving me the "Python development files are not installed. Please add the development files, or repair your existing installation." error – Romero May 06 '20 at 16:47

0 Answers0