OpenWrt Forum Archive

Topic: configure wants to run C program as test but cannot in cross-compile

The content of this topic has been archived on 26 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi.  This is my first attempt at building a package.  I'm trying to compile Python.  Everything was going great until this error:

checking for %zd printf() format support... configure: error: cannot run test program while cross compiling

I took a look inside the configure.in file (http://svn.python.org/projects/python/t … nfigure.in), and discovered the following:

AC_MSG_CHECKING(for %zd printf() format support)
AC_TRY_RUN([#include <stdio.h>
#include <stddef.h>
#include <string.h>

int main()
{
    char buffer[256];

#ifdef HAVE_SSIZE_T
typedef ssize_t Py_ssize_t;
#elif SIZEOF_VOID_P == SIZEOF_LONG
typedef long Py_ssize_t;
#else
typedef int Py_ssize_t;
#endif

    if(sprintf(buffer, "%zd", (size_t)123) < 0)
           return 1;

    if (strcmp(buffer, "123"))
    return 1;

    if (sprintf(buffer, "%zd", (Py_ssize_t)-123) < 0)
           return 1;

    if (strcmp(buffer, "-123"))
    return 1;

    return 0;
}],
[AC_MSG_RESULT(yes)
 AC_DEFINE(PY_FORMAT_SIZE_T, "z", [Define to printf format modifier for Py_ssize_t])],
 AC_MSG_RESULT(no))

As you can see, it is attempting to run a small C program to check whether this printf feature is available on the architecture, but it can't because I'm not compiling on the architecture.  At this point I'm out of my depth.  Does anybody know what the result of this test should be on mipsel, and how to hardcode that into the configure.in file?  Going to need to put that in a patch to make the package compile.

You can compile that small code using ./staging_dir_mipsel/bin/mipsel-linux-uclibc-gcc (from the BuildRoot or the SDK), it will create an executable that you can copy to your openwrt system, and run it. I've did that, it returned with 0, so it looks like uClibc has that z modifier implemented.
My suggestion about configure.in, that you replace that whole section you just copy-pasted with a single line:

AC_DEFINE(PY_FORMAT_SIZE_T, "z", [Define to printf format modifier for Py_ssize_t])

and then run autoconf. Next time you run configure, it'll set that variable in pyconfig.h, without running that little code. Now you can make a patch from the resulting configure and/or configure.in, place it in your patches directory, and you're done. wink

(Last edited by lazics on 6 Jun 2007, 22:08)

The discussion might have continued from here.