2 years ago

#57449

test-img

Malma

Undefined reference to PyAST_mod2obj

So i'm doing some stuff with python c api. I'm trying to parse a string with function PyParser_ASTFromString

There is no error here, I then tried to change mod_ty i got to PyObject* with functiin PyAST_mod2obj

I then compile it with the command:

gcc src\main.c -IC:\Users\Malma\AppData\Local\Programs\Python\Python39\include -LC:\Users\Malma\AppData\Local\Programs\Python\Python39\libs -lpython -lpython39 -Wall

then i get error:

undefined reference to `PyAST_mod2obj'

My full code:

#include <Python.h>
#include <Python-ast.h>

int main(int argc, char** argv) {
    Py_Initialize();

    PyArena* arena = PyArena_New();

    mod_ty mod = PyParser_ASTFromString("x = 6", "<string>", Py_file_input, NULL, arena);

    PyObject* result = PyAST_mod2obj(mod);
    printf("%s\n", result->ob_type->tp_name);
    
    PyArena_Free(arena);
    
    return 0;
}

python

c

python-c-api

0 Answers

Your Answer

Accepted video resources