Simon Josefsson | 21 Apr 13:10 2010

test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

While debugging a 'asprintf' bug on Windows, I noticed that building the
'vasprintf' module fails:

gnulib-tool --create-testdir --dir m --with-tests vasprintf
cd m
./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu 
make

results in:

g++ -DHAVE_CONFIG_H -I.  -DGNULIB_STRICT_CHECKING=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib    -MT
test-string-c++2.o -MD -MP -MF .deps/test-string-c++2.Tpo -c -o test-string-c++2.o test-string-c++2.cc
mv -f .deps/test-string-c++2.Tpo .deps/test-string-c++2.Po
g++     -o test-string-c++.exe test-string-c++.o test-string-c++2.o ../gllib/libgnu.a  
test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'
test-string-c++.o:(.rodata+0x0): undefined reference to `rpl_memchr'
test-string-c++2.o:(.rodata+0x0): undefined reference to `rpl_memchr'
collect2: ld returned 1 exit status
make[4]: *** [test-string-c++.exe] Error 1
make[4]: Leaving directory `/home/jas/src/gnulib/m/gltests'

Ideas?

/Simon

Bruno Haible | 22 Apr 02:09 2010

Re: test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

Hi Simon,

> While debugging a 'asprintf' bug on Windows, I noticed that building the
> 'vasprintf' module fails:
> 
> gnulib-tool --create-testdir --dir m --with-tests vasprintf
> cd m
> ./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu 
> make
> 
> results in:
> 
> g++ -DHAVE_CONFIG_H -I.  -DGNULIB_STRICT_CHECKING=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib    -MT
test-string-c++2.o -MD -MP -MF .deps/test-string-c++2.Tpo -c -o test-string-c++2.o test-string-c++2.cc
> mv -f .deps/test-string-c++2.Tpo .deps/test-string-c++2.Po
> g++     -o test-string-c++.exe test-string-c++.o test-string-c++2.o ../gllib/libgnu.a  
> test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'
> test-string-c++.o:(.rodata+0x0): undefined reference to `rpl_memchr'
> test-string-c++2.o:(.rodata+0x0): undefined reference to `rpl_memchr'
> collect2: ld returned 1 exit status
> make[4]: *** [test-string-c++.exe] Error 1
> make[4]: Leaving directory `/home/jas/src/gnulib/m/gltests'

Can you show the result of 'grep MEMCHR config.status' and the relevant
portion of gllib/string.h ?

In two native mingw builds, one with default settings and one with
gl_cv_func_memchr_works=no, I could not reproduce your problem.

Bruno
(Continue reading)

Simon Josefsson | 22 Apr 08:55 2010

Re: test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

Bruno Haible <bruno <at> clisp.org> writes:

> Hi Simon,
>
>> While debugging a 'asprintf' bug on Windows, I noticed that building the
>> 'vasprintf' module fails:
>> 
>> gnulib-tool --create-testdir --dir m --with-tests vasprintf
>> cd m
>> ./configure --host=i586-mingw32msvc --build=i686-pc-linux-gnu 
>> make
>> 
>> results in:
>> 
>> g++ -DHAVE_CONFIG_H -I.  -DGNULIB_STRICT_CHECKING=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib    -MT
test-string-c++2.o -MD -MP -MF .deps/test-string-c++2.Tpo -c -o test-string-c++2.o test-string-c++2.cc
>> mv -f .deps/test-string-c++2.Tpo .deps/test-string-c++2.Po
>> g++     -o test-string-c++.exe test-string-c++.o test-string-c++2.o ../gllib/libgnu.a  
>> test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'
>> test-string-c++.o:(.rodata+0x0): undefined reference to `rpl_memchr'
>> test-string-c++2.o:(.rodata+0x0): undefined reference to `rpl_memchr'
>> collect2: ld returned 1 exit status
>> make[4]: *** [test-string-c++.exe] Error 1
>> make[4]: Leaving directory `/home/jas/src/gnulib/m/gltests'
>
> Can you show the result of 'grep MEMCHR config.status' and the relevant
> portion of gllib/string.h ?

S["REPLACE_MEMCHR"]="1"
S["HAVE_RAWMEMCHR"]="1"
(Continue reading)

Bruno Haible | 22 Apr 10:37 2010

Re: test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

> > Can you show the result of 'grep MEMCHR config.status' and the relevant
> > portion of gllib/string.h ?
> 
> S["REPLACE_MEMCHR"]="1"
> S["HAVE_RAWMEMCHR"]="1"
> S["HAVE_MEMCHR"]="1"
> S["GNULIB_RAWMEMCHR"]="0"
> S["GNULIB_MEMCHR"]="1"
> D["HAVE_MEMCHR"]=" 1"
> D["GNULIB_TEST_MEMCHR"]=" 1"
> 
> See below for string.h contents.

Thanks, this is as expected for a cross-compile. Two more pieces of data
are needed:

   $ nm gllib/libgnu.a | grep memchr

   $ nm gllib/memchr.o

Bruno

Simon Josefsson | 22 Apr 10:43 2010

Re: test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

Bruno Haible <bruno <at> clisp.org> writes:

>> > Can you show the result of 'grep MEMCHR config.status' and the relevant
>> > portion of gllib/string.h ?
>> 
>> S["REPLACE_MEMCHR"]="1"
>> S["HAVE_RAWMEMCHR"]="1"
>> S["HAVE_MEMCHR"]="1"
>> S["GNULIB_RAWMEMCHR"]="0"
>> S["GNULIB_MEMCHR"]="1"
>> D["HAVE_MEMCHR"]=" 1"
>> D["GNULIB_TEST_MEMCHR"]=" 1"
>> 
>> See below for string.h contents.
>
> Thanks, this is as expected for a cross-compile. Two more pieces of data
> are needed:
>
>    $ nm gllib/libgnu.a | grep memchr
>
>    $ nm gllib/memchr.o

jas <at> mocca:~/src/gnulib/m master$ i586-mingw32msvc-nm gllib/libgnu.a | grep memchr
memchr.o:
00000000 T _rpl_memchr
         U _rpl_memchr
jas <at> mocca:~/src/gnulib/m master$ i586-mingw32msvc-nm gllib/memchr.o
00000000 b .bss
00000000 d .data
00000000 N .debug_abbrev
(Continue reading)

Bruno Haible | 23 Apr 01:01 2010

Re: test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

Simon Josefsson wrote:
> jas <at> mocca:~/src/gnulib/m master$ i586-mingw32msvc-nm gllib/libgnu.a | grep memchr
> memchr.o:
> 00000000 T _rpl_memchr
>          U _rpl_memchr
> jas <at> mocca:~/src/gnulib/m master$ i586-mingw32msvc-nm gllib/memchr.o
> 00000000 b .bss
> 00000000 d .data
> 00000000 N .debug_abbrev
> 00000000 N .debug_aranges
> 00000000 N .debug_frame
> 00000000 N .debug_info
> 00000000 N .debug_line
> 00000000 N .debug_loc
> 00000000 N .debug_pubnames
> 00000000 N .debug_ranges
> 00000000 t .text
> 00000000 T _rpl_memchr

OK, this proves that everything is fine with the 'memchr' module and that the
problem is with the linking with libgnu.a. So let's look again at this line:

> g++     -o test-string-c++.exe test-string-c++.o test-string-c++2.o ../gllib/libgnu.a  
> test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

Why is CXX="g++" being used when you are cross-compiling from linux to mingw??

Did you specify a CXX to configure? Or did configure find nothing usable
because you haven't installed a 'i586-mingw32msvc-g++'?

(Continue reading)

Simon Josefsson | 23 Apr 11:13 2010

Re: test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

Bruno Haible <bruno <at> clisp.org> writes:

>> g++     -o test-string-c++.exe test-string-c++.o test-string-c++2.o ../gllib/libgnu.a  
>> test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'
>
> Why is CXX="g++" being used when you are cross-compiling from linux to mingw??

Ah, that's the problem.

> Did you specify a CXX to configure?

No, just the commands shown in the first post.

> Or did configure find nothing usable because you haven't installed a
> 'i586-mingw32msvc-g++'?

It is installed, but configure.ac doesn't call AC_PROG_CXX so it never
checks for that tool.  Adding AC_PROG_CXX to gltests/configure.ac solves
the problem.  I see that ansi-c++-opt.m4 may be attempting to do setup a
C++ compiler, but it doesn't seem to work when cross-compiling.

/Simon

Bruno Haible | 24 Apr 16:15 2010

Re: test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

Simon Josefsson wrote:
> Adding AC_PROG_CXX to gltests/configure.ac solves
> the problem.  I see that ansi-c++-opt.m4 may be attempting to do setup a
> C++ compiler, but it doesn't seem to work when cross-compiling.

Well spotted! This should fix it:

2010-04-24  Bruno Haible  <bruno <at> clisp.org>

	ansi-c++-opt: Find correct compiler when cross-compiling.
	* m4/ansi-c++.m4 (gl_PROG_ANSI_CXX): Use AC_CHECK_TOOLS instead of
	AC_CHECK_PROGS.
	Reported by Simon Josefsson.

--- m4/ansi-c++.m4.orig	Sat Apr 24 16:12:38 2010
+++ m4/ansi-c++.m4	Sat Apr 24 16:12:23 2010
 <at>  <at>  -1,4 +1,4  <at>  <at> 
-# ansi-c++.m4 serial 4
+# ansi-c++.m4 serial 5
 dnl Copyright (C) 2002-2003, 2005, 2010 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 <at>  <at>  -48,7 +48,9  <at>  <at> 
     if test -n "$CCC"; then
       CXX="$CCC"
     else
-      AC_CHECK_PROGS([CXX], [g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC], [:])
+      AC_CHECK_TOOLS([CXX],
+                     [g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC],
+                     [:])
(Continue reading)

Simon Josefsson | 25 Apr 11:43 2010

Re: test-string-c++.o:(.data+0x0): undefined reference to `rpl_memchr'

Bruno Haible <bruno <at> clisp.org> writes:

> Simon Josefsson wrote:
>> Adding AC_PROG_CXX to gltests/configure.ac solves
>> the problem.  I see that ansi-c++-opt.m4 may be attempting to do setup a
>> C++ compiler, but it doesn't seem to work when cross-compiling.
>
> Well spotted! This should fix it:

It works.  Thanks!

/Simon


Gmane