I can successfully get it to compile and print out the value with some modifcation:
#include <Python.h>
#include <stdio.h>
int
main (int argc, char *argv[])
{
PyObject *pName, *pModule, *pFunc;
PyObject *pValue;
Py_Initialize ();
pName = PyUnicode_FromString ("uuid");
pModule = PyImport_Import (pName);
Py_DECREF (pName);
pFunc = PyObject_GetAttrString (pModule, "uuid4");
pValue = PyObject_CallObject (pFunc, NULL);
PyObject_Print(pValue, stdout, Py_PRINT_RAW); // my change
printf ("\n"); // make the printout look nicer
Py_Finalize ();
return 0;
}
And here is the output:
$ ./a.out
bd94cb52-9278-41a8-bc5a-ad05eff91188
I think the cause of your problem is most likely this: The compiler that compiled python is not the same as the one you used to compile your test program test.c
. You can either find out the right version of gcc to compile your code, or simply recompile python3.4 with your current gcc compiler.
As for your original version of test.c, it gives this error on my MBP:
$ ./a.out
(null)
Exception ignored in: <module 'threading' from '/usr/local/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py'>
Traceback (most recent call last):
File "/usr/local/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 1292, in _shutdown
t = _pickSomeNonDaemonThread()
File "/usr/local/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 1299, in _pickSomeNonDaemonThread
for t in enumerate():
File "/usr/local/Frameworks/Python.framework/Versions/3.4/lib/python3.4/threading.py", line 1269, in enumerate
return list(_active.values()) + list(_limbo.values())
TypeError: bad argument type for built-in operation
I don't really know what is going on.