I have a c program that I need to compile and use in the middle of a python code. it is not c++ program so I assume I should change this syntax for compiling because I get a lot of errors related to not having "main()" in the program which is just because it is a c (not c++)for a x86_64 Mac system?
how should I change this syntax for a program.c code?
g++ -o program.x program.c
1 Answer 1
Your C code should be compiled into a shared library:
gcc -shared -o program.so -Wall -Wextra -fPIC -O2 -DNDEBUG program.c
And then you can use ctypes module to invoke functions in your library from Python.
answered Oct 3, 2012 at 8:43
Maxim Egorushkin
138k19 gold badges201 silver badges293 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
0xC0000022L
Shouldn't this be
.dylib on a Mac?Maxim Egorushkin
It probably can have any extension since when loading the shared library in Python one can specify the full path. But you may be right in general, I only ever use Macs with Linux.
lang-c
Boost::Pythonand am not looking back.