Discussion:
Problems with getopt
(too old to reply)
Christian Egli
2017-04-19 13:41:26 UTC
Permalink
Raw Message
Hi all

I'm using the latest checkout from gnulib an I'm trying to upgrade to
it. However when I cross-compile my project under mingw I get a
compilation error in gnulib/getopt.c:

i686-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -I../liblouis -I../liblouis -I../tools/gnulib -I../tools/gnulib -g -O2 -Wl,--add-stdcall-alias -MT lou_allround.o -MD -MP -MF .deps/lou_allround.Tpo -c -o lou_allround.o lou_allround.c
mv -f .deps/lou_allround.Tpo .deps/lou_allround.Po
/bin/bash ../libtool --tag=CC --mode=link i686-w64-mingw32-gcc -g -O2 -Wl,--add-stdcall-alias -avoid-version -Xcompiler -static-libgcc -o lou_allround.exe lou_allround.o ../liblouis/liblouis.la ../tools/gnulib/libgnutools.la ../tools/libbrlcheck.la
libtool: link: i686-w64-mingw32-gcc -g -O2 -Wl,--add-stdcall-alias -static-libgcc -o .libs/lou_allround.exe lou_allround.o ../liblouis/.libs/liblouis.dll.a ../tools/gnulib/.libs/libgnutools.a ../tools/.libs/libbrlcheck.a /home/eglic/src/liblouis/liblouis/.libs/liblouis.dll.a -L/tmp/liblouis-mingw32/lib
../tools/gnulib/.libs/libgnutools.a(getopt.o): In function `process_long_option':
/home/eglic/src/liblouis/tools/gnulib/getopt.c:281: undefined reference to `flockfile'
/home/eglic/src/liblouis/tools/gnulib/getopt.c:295: undefined reference to `funlockfile'
collect2: error: ld returned 1 exit status
Makefile:1098: recipe for target 'lou_allround.exe' failed

I do not fully understand the source of gnulib/getopt.c but could it be
that

# ifndef _POSIX_THREAD_SAFE_FUNCTIONS
# define flockfile(fp) /* nop */
# define funlockfile(fp) /* nop */
# endif

is not invoked when cross-compiling with mingw?

Thanks
Christian
--
Christian Egli
Swiss Library for the Blind, Visually Impaired and Print Disabled
Grubenstrasse 12, CH-8045 Zürich, Switzerland
Gisle Vanem
2017-04-19 16:54:41 UTC
Permalink
Raw Message
Post by Christian Egli
/home/eglic/src/liblouis/tools/gnulib/getopt.c:281: undefined reference to `flockfile'
/home/eglic/src/liblouis/tools/gnulib/getopt.c:295: undefined reference to `funlockfile'
collect2: error: ld returned 1 exit status
Makefile:1098: recipe for target 'lou_allround.exe' failed
I do not fully understand the source of gnulib/getopt.c but could it be
that
# ifndef _POSIX_THREAD_SAFE_FUNCTIONS
# define flockfile(fp) /* nop */
# define funlockfile(fp) /* nop */
# endif
is not invoked when cross-compiling with mingw?
Nothing to do with that. I got the same error. Since most modern
MinGW uses win-pthreads, they define:
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L

in their <pthread_unistd.h> (line:150). So I think Gnulib should
just say:

# if !HAVE_DECL_FLOCKFILE
# define flockfile(fp) /* nop */
# define funlockfile(fp) /* nop */
# endif

instead. Similar to getdelim.c etc.
--
--gv
Loading...