[Numpy-discussion] checking for c compiler during build

Skipper Seabold jsseabold at gmail.com
Wed Mar 7 14:03:45 EST 2012


On Wed, Mar 7, 2012 at 12:35 PM, Skipper Seabold <jsseabold at gmail.com> wrote:
> Is there a way to use numpy.distuils to programmatically check for a C
> compiler at build time in a platform independent way?

Wading through the numpy/distutils code some more. Would something as
simple as this work all the time? Seems to do the trick for me.

from distutils.dist import Distribution
from distutils.command.config import config as distutils_config
from distutils import log

dummy_c_text = r'''
void do_nothing(void);
int main(void) {
    do_nothing();
    return 0;
}
'''

def has_c_compiler():
    c = distutils_config(Distribution())
    try:
        success = c.try_compile(dummy_c_text)
        return True
    except:
        log.info("No C compiler detected of files.")
        return False

Skipper



More information about the NumPy-Discussion mailing list