Suppose I want to use gcc from the command line to compile a Python C extension. I would structure the call like this:
gcc -o applesauce.pyd -IC:/Python35/include -LC:/Python35/libs -l python35 applesauce.c
I noticed that the -I , -L and -L options are absolutely necessary, otherwise you will get an error message. These commands tell gcc where to look for headers ( -I ), where to look for static libraries ( -L ) and which static library to use on actually ( python35 , which actually translates to libpython35.a ).
Now, it is really very easy to get the libs and include directories if this is your machine, as they never change unless you want to. However, I wrote a program that calls gcc from the command line that other people will use. The line in which this call occurs looks something like this:
from subprocess import call import sys filename = applesauce.c include_directory = os.path.join(sys.exec_prefix, 'include') libs_directory = os.path.join(sys.exec_prefix, 'libs') call(['gcc', ..., '-I', include_direcory, '-L', libs_directory, ...])
However, others will have different platforms and different Python installation structures, so just connecting to them will not always work.
Instead, I need a solution from Python that will reliably return include and libs directories.
Edit:
I looked at the distutils.ccompiler module and found many useful functions that distutils would use in part, but make it customizable for me so that my compiler completely steps over the platform. The only thing I need is to pass the include and runtime libraries to it ...
Edit 2:
I looked at distutils.sysconfig and I can reliably return the include directory, including all header files. I still don't know how to get the runtime library.
The distutils.ccompiler docs distutils.ccompiler here
A program that needs this feature is called Cyther.