简体   繁体   中英

Crosscompiling C for windows on linux, getting a compiler error

All,

I'm using the mingw32 tool chain to do some cross compiling on a linux platform. Everything has been working out fine, until I included <error.h> from the standard library. Now mingw32 spits out a compiler error, saying it can't find error.h .

While this is a GNU extension, I'm also using GNU getopts.h , which does work. So, why do I get this problem? Following is a verbose output:

[09:57:48]$ i586-mingw32msvc-gcc scanner.c -O -Wall  -o brookfieldSplitter.exe -v 2>&1 | sed ':1;s,/[^/.][^/]*/\\.\\./,/,;t 1'
Using built-in specs.
Target: i586-mingw32msvc
Configured with: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libs
Thread model: win32
gcc version 4.2.1-sjlj (mingw32-2)
 /usr/libexec/gcc/i586-mingw32msvc/4.2.1-sjlj/cc1 -quiet -v scanner.c -quiet -dumpbase scanner.c -mtune=pentium -auxbase scanner -O -Wall -version -o /tmp/cc4itePc.s
ignoring nonexistent directory "/usr/i586-mingw32msvc/sys-include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/include
 /usr/i586-mingw32msvc/include
End of search list.
GNU C version 4.2.1-sjlj (mingw32-2) (i586-mingw32msvc)
        compiled by GNU C version 4.4.4.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 593b76e6db3b48c579d5ccd7737af5b4
scanner.l:53:19: error: error.h: No such file or directory
scanner.l: In function 'main':
scanner.l:638: warning: implicit declaration of function 'error'

As noted on this mingw32 wiki page , there are differences between the search paths for gcc and mingw32. You can see in the above output where it searches for #include items.

Contents of locate error.h as requested:

[10:44:42]$ locate error.h
/usr/i586-mingw32msvc/include/raserror.h
/usr/i586-mingw32msvc/include/winerror.h
/usr/include/error.h
/usr/include/glib-2.0/gio/gdbuserror.h
/usr/include/glib-2.0/gio/gioerror.h
/usr/include/glib-2.0/glib/gerror.h
/usr/include/i386-linux-gnu/bits/error.h
/usr/include/linux/can/error.h
/usr/lib/syslinux/com32/include/gplinclude/disk/error.h
/usr/share/doc/ipython/manual/html/api/generated/IPython.kernel.core.error.html
/usr/share/doc/ipython/manual/html/api/generated/IPython.kernel.error.html
/usr/share/pgadmin3/docs/cs_CZ/connect-error.html
/usr/share/pgadmin3/docs/en_US/connect-error.html
/usr/share/pgadmin3/docs/fr_FR/connect-error.html
/usr/share/webkitgtk-1.0/webkit-1.0/resources/error.html
/usr/share/webkitgtk-3.0/webkit-3.0/resources/error.html
/usr/src/linux-headers-3.0.0-12/arch/ia64/sn/include/ioerror.h
/usr/src/linux-headers-3.0.0-12/arch/mips/include/asm/fw/cfe/cfe_error.h
/usr/src/linux-headers-3.0.0-12/include/linux/can/error.h
/usr/src/linux-headers-3.0.0-12-generic/include/config/ata/verbose/error.h

Why does mingw32 include the GNU extension getopt but not error ? As noted by Ignacio below, getopt is POSIX. And what is the easiest way to work around this problem?

  • Drop to ISO C?
  • Add /usr/include to search path for compiler?
  • Copy error into /usr/i586-mingw32msvc/include/ ?

The header error.h , as you linked in your last comment at the time of this writing, is part of GNU libc, aka glibc, aka the GNU system's C library.

You are compiling for Windows , it does not have GNU libc, it uses msvcr*. You cannot magically cross-compile Linux/GNU code like this and expect it to work.

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