I have a very similar issue to this SO post; however, after implementing the proposed fix there - I still get the below error.
I'm trying to compile a C file that's been generated by Cython.
cython ConnectFour.pyx --embed
I try to compile my c file like so:
gcc -I /usr/local/Cellar/python3/3.7.0/Frameworks/Python.framework/Versions/3.7/Headers -o ConnectFour ConnectFour.c
However I get the following errors:
Undefined symbols for architecture x86_64:
"_PyBaseObject_Type", referenced from:
___Pyx_InBases in ConnectFour-3c26d7.o
"_PyBytes_FromStringAndSize", referenced from:
___pyx_pymod_exec_ConnectFour in ConnectFour-3c26d7.o
___Pyx_InitStrings in ConnectFour-3c26d7.o
"_PyCFunction_NewEx", referenced from:
___pyx_pymod_exec_ConnectFour in ConnectFour-3c26d7.o
"_PyCFunction_Type", referenced from:
___Pyx_PyObject_CallOneArg in ConnectFour-3c26d7.o
___Pyx_PyObject_CallNoArg in ConnectFour-3c26d7.o
___Pyx_PyObject_Call2Args in ConnectFour-3c26d7.o
___Pyx_PyCFunction_FastCall in ConnectFour-3c26d7.o
___pyx_pf_11ConnectFour_36eval_heuristic_score in ConnectFour-3c26d7.o
___pyx_pf_11ConnectFour_38list_valid_col_idxs in ConnectFour-3c26d7.o
___pyx_pf_11ConnectFour_40deep_copy_board in ConnectFour-3c26d7.o
...
"_PyCode_New", referenced from:
___Pyx_InitCachedConstants in ConnectFour-3c26d7.o
___Pyx_CreateCodeObjectForTraceback in ConnectFour-3c26d7.o
"_PyDict_Copy", referenced from:
___pyx_pw_11ConnectFour_7profile_1wrapper in ConnectFour-3c26d7.o
___pyx_pw_11ConnectFour_5timer_1wrapper in ConnectFour-3c26d7.o
"_PyDict_GetItemString", referenced from:
___pyx_pymod_exec_ConnectFour in ConnectFour-3c26d7.o
"_PyDict_GetItemWithError", referenced from:
___Pyx_PyDict_GetItem in ConnectFour-3c26d7.o
"_PyDict_New", referenced from:
___pyx_pymod_exec_ConnectFour in ConnectFour-3c26d7.o
___Pyx_Import in ConnectFour-3c26d7.o
___Pyx_CyFunction_get_dict in ConnectFour-3c26d7.o
___Pyx_CyFunction_get_annotations in ConnectFour-3c26d7.o
___pyx_pf_11ConnectFour_28count_players in ConnectFour-3c26d7.o
___pyx_pf_11ConnectFour_52num_in_a_row in ConnectFour-3c26d7.o
I appears based on this and this SO post that I'm missing some library links? So I tried the following.
gcc -I /usr/local/Cellar/python3/3.7.0/Frameworks/Python.framework/Versions/3.7/Headers -o ConnectFour ConnectFour.c -l/usr/local/Cellar/python3/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib
And now I get a lib not found error.
ld: library not found for -l/usr/local/Cellar/python3/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib
I'm totally out of my depth here reading all these SO posts (first time dealing with C) so will appreciate step by step answers.
What do I need to have in order to compile and then run my C file without error-ing out?
I know that my headers are located in /usr/local/Cellar/python3/3.7.0/Frameworks/Python.framework/Versions/3.7/Headers
and the library is located in /usr/local/Cellar/python3/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/libpython3.7.dylib
I'm on OSX and I installed Python using Homebrew.