简体   繁体   中英

How to force autoconf to not define a macro?

I regularly run into this problem while building C projects that use autoconf so I'm looking for a repeatable way to do this. I often have a library where I'd like to undef a macro that is generated by autoheader in a config.h file. For example - right now I want to make sure that #define CLOCK_GETTIME 1 is generated as #undef CLOCK_GETTIME .

Assume in this example the clock_gettime is checked like so.

AC_CHECK_FUNCS([clock_gettime])

In the past I manually edit the file to remove defines. But I can't believe there isn't something I cant just pass to ./configure to override the default behavior of AC_CHECK_FUNCS .

How do I change what autoconf decides to define in my config.h ?

./configure 'ac_cv_func_clock_gettime=no' should work. For example:

mkdir foo
cd foo
printf '%s\n' \
    'AC_INIT([foo], [0.1])' \
    'AC_CONFIG_HEADERS([config.h])' \
    'AC_CHECK_FUNCS([clock_gettime])' \
    'AC_OUTPUT' \
    > configure.ac
autoheader
autoconf
./configure >/dev/null 2>&1 \
    && grep CLOCK_GETTIME config.h
./configure 'ac_cv_func_clock_gettime=no' >/dev/null 2>&1 \
    && grep CLOCK_GETTIME config.h

Output on my system:

#define HAVE_CLOCK_GETTIME 1
/* #undef HAVE_CLOCK_GETTIME */

All cache variables created by AC_CHECK_FUNC , AC_CHECK_FUNCS , and AC_CHECK_FUNCS_ONCE have a general form described in the official documentation :

This macro caches its result in the ac_cv_func_ function variable.

Here are some more examples:

ac_cv_func_strcasecmp        # AC_CHECK_FUNC([strcasecmp])
ac_cv_func_mempcpy           # AC_CHECK_FUNC([mempcpy])
ac_cv_func_pthread_create    # AC_CHECK_FUNC([pthread_create])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM