Solution for 'struct timespec' error in PyObjects C when creating a shared file .so

81 Views Asked by At

I'm trying to create my own custom C function to run in a .py function making a shared library, but I keep getting error

my 100-print_python_list_info.c code is:

#include <stdio.h>
#include <time.h>
#include <Python.h>


/**
 * print_python_list_info - is function prints info about python list
 * @p: object
 * Return: void nothing.
 */
void print_python_list_info(PyObject *p)
{
        long int size, index = 0, allocations;
        PyObject *obj;

        size = PyList_Size(p);
        allocations = ((PyListObject *)p)->allocated;

        printf("[*] Size of the Python List = %ld\n", size);
        printf("[*] Allocated = %ld\n", allocations);

        for (index = 0; index < size; index++)
        {       obj = PyList_GetItem(p, index);
                printf("Element %ld: %s\n", index, Py_TYPE(obj)->tp_name);
        }
}

i run this in my bash terminal:

gcc -Wall -Werror -Wextra -pedantic -std=c99 -shared -Wl,-soname,PyList -o libPyList.so -fPIC -I/usr/include/python3.10 100-print_python_list_info.c

output:

In file included from /usr/include/python3.10/Python.h:118,
                 from 100-print_python_list_info.c:3:
/usr/include/python3.10/cpython/pytime.h:150:60: error: 'struct timespec' declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
  150 | PyAPI_FUNC(int) _PyTime_FromTimespec(_PyTime_t *tp, struct timespec *ts);
      |                                                            ^~~~~~~~
/usr/include/python3.10/cpython/pytime.h:155:56: error: 'struct timespec' declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
  155 | PyAPI_FUNC(int) _PyTime_AsTimespec(_PyTime_t t, struct timespec *ts);
0

There are 0 best solutions below