Subject: linking C programs with C++ libraries
To: None <tech-toolchain@netbsd.org>
From: Klaus Heinz <k.heinz.nov.zwei@onlinehome.de>
List: tech-toolchain
Date: 11/26/2002 22:05:55
Hi,

while trying to update a package (textproc/icu) I get the following
error:

  cc -O0 -g -I/usr/pkg/include -Wall -ansi -pedantic -Wshadow
  -Wpointer-arith -Wmissing-prototypes -Wwrite-strings -Wl,-R/usr/pkg/lib
  -L/usr/pkg/lib  -o genrb errmsg.o genrb.o parse.o read.o reslist.o
  ustr.o util.o wrtjava.o rle.o -L../../i18n -licui18n
  -L../../tools/toolutil -licutoolutil -L../../common -licuuc
  -L../../data/out -L../../stubdata -licudata -lm
  /usr/lib/libstdc++.so: undefined reference to `__builtin_vec_new'
  /usr/lib/libstdc++.so: undefined reference to `__builtin_vec_delete'
  /usr/lib/libstdc++.so: undefined reference to `__builtin_new'
  collect2: ld returned 1 exit status

This happens on NetBSD/i386 1.5.4_ALPHA both with egcs-1.1.2 (in
/usr/bin/) and with gcc 2.95.3 (from pkgsrc). At the moment I have no
sufficiently fast machine to test this behaviour with 1.6 or -current.

If I let the package use 'c++' instead of 'cc' for this link stage,
there is no problem, probably because 'c++' makes 'ld' also link
against libgcc.a while 'cc' does not.

I have asked about this behaviour on the appropriate mailing list for
the package, which is supported for multiple OS/compiler combinations
(among them various flavours of GCC 2 for RedHat Linux, FreeBSD, Solaris
2.6 and MacOS X) and they tell me that

  "This is the proper way to create C programs for most platforms even
  when a C++ library is used."

I will do more tests with a FreeBSD installation I still have but I
would like to know whether the NetBSD compiler is really _that_
different from its incarnations on other platforms.

I would have expected the compiler from pkgsrc not to be extensively
patched for NetBSD but it behaves the same way as the builtin compiler,
which makes me doubt the statement from the mailing list.

ciao
     Klaus