Subject: bug#29298: C++ compiler, Newlib and "implicit declaration of function '_spawnv'"

From: Jeffrey Walton <[email-masked]>
Date: Tue, 14 Nov 2017 12:08:44 -0500

On Tue, Nov 14, 2017 at 11:57 AM, Jeffrey Walton <[email-masked]> wrote:
> Hi Everyone,
>
> We are testing an Autotools front-end on MSYS2. The download is
> available from https://mingw-w64.org/.
>
> ...
> /bin/sh ./libtool  --tag=CXX   --mode=link g++ -pthread
> -fdata-sections -ffunction-sections -pipe
> -DCRYPTOPP_DATA_DIR='"@pkgdatadir@/cryptopp/"' -g -O2 -pthread
> -Wl,--gc-sections  -o cryptest.exe cryptest-test.o cryptest-bench1.o
> cryptest-bench2.o cryptest-validat0.o cryptest-validat1.o
> cryptest-validat2.o cryptest-validat3.o cryptest-datatest.o
> cryptest-regtest1.o cryptest-regtest2.o cryptest-regtest3.o
> cryptest-dlltest.o cryptest-fipsalgt.o cryptest-adhoc.o libcryptopp.la
> /bin/sh ./libtool  --tag=CXX   --mode=link g++ -pthread
> -fdata-sections -ffunction-sections -pipe -g -O2 -pthread
> -Wl,--gc-sections  -o cryptestcwd.exe cryptestcwd-test.o
> cryptestcwd-bench1.o cryptestcwd-bench2.o cryptestcwd-validat0.o
> cryptestcwd-validat1.o cryptestcwd-validat2.o cryptestcwd-validat3.o
> cryptestcwd-datatest.o cryptestcwd-regtest1.o cryptestcwd-regtest2.o
> cryptestcwd-regtest3.o cryptestcwd-dlltest.o cryptestcwd-fipsalgt.o
> cryptestcwd-adhoc.o libcryptopp.la
> libtool: link: g++ -pthread -fdata-sections -ffunction-sections -pipe
> -g -O2 -pthread -Wl,--gc-sections -o .libs/cryptestcwd.exe
> cryptestcwd-test.o cryptestcwd-bench1.o cryptestcwd-bench2.o
> cryptestcwd-validat0.o cryptestcwd-validat1.o cryptestcwd-validat2.o
> cryptestcwd-validat3.o cryptestcwd-datatest.o cryptestcwd-regtest1.o
> cryptestcwd-regtest2.o cryptestcwd-regtest3.o cryptestcwd-dlltest.o
> cryptestcwd-fipsalgt.o cryptestcwd-adhoc.o  ./.libs/libcryptopp.a
> -pthread
> libtool: link: g++ -pthread -fdata-sections -ffunction-sections -pipe
> -DCRYPTOPP_DATA_DIR=\"@pkgdatadir@/cryptopp/\" -g -O2 -pthread
> -Wl,--gc-sections -o .libs/cryptest.exe cryptest-test.o
> cryptest-bench1.o cryptest-bench2.o cryptest-validat0.o
> cryptest-validat1.o cryptest-validat2.o cryptest-validat3.o
> cryptest-datatest.o cryptest-regtest1.o cryptest-regtest2.o
> cryptest-regtest3.o cryptest-dlltest.o cryptest-fipsalgt.o
> cryptest-adhoc.o  ./.libs/libcryptopp.a -pthread
> ./.libs/lt-cryptestcwd.c: In function 'main':
> ./.libs/lt-cryptest.c: In function 'main':
> ./.libs/lt-cryptestcwd.c:319:16: warning: implicit declaration of
> function '_spawnv' [-Wimplicit-function-declaration]
>    rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
>                 ^~~~~~~
> ./.libs/lt-cryptest.c:319:16: warning: implicit declaration of
> function '_spawn ' [-Wimplicit-function-declaration]
>    rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);
>                 ^~~~~~~
> /tmp/ccFfsaBb.o: In function `main':
> /home/cryptopp/./.libs/lt-cryptest.c:319: undefined reference to `_spawnv'
> /home/cryptopp/./.libs/lt-cryptest.c:319:(.text.startup+0x4b4):
> relocation truncated to fit: R_X86_64_PC32 against undefined symbol
> `_spawnv'
> collect2: error: ld returned 1 exit status
> /tmp/ccfJfnlw.o: In function `main':
> /home/cryptopp/./.libs/lt-cryptestcwd.c:319: undefined reference to `_spawnv'
> /home/cryptopp/./.libs/lt-cryptestcwd.c:319:(.text.startup+0x4b4):
> relocation truncated to fit: R_X86_64_PC32 against undefined symbol
> `_spawnv'
> strip: './cryptest.exe': No such file
> collect2: error: ld returned 1 exit status
> strip: './cryptestcwd.exe': No such file
> ./libtool: line 11083: ./cryptest.exe: No such file or directory
> ./libtool: line 11083: ./cryptestcwd.exe: No such file or directory
> make[1]: Leaving directory '/home/cryptopp'

Looking at the flags selected by libtool, I think there's another bug
present (correct me if I am wrong)...

When C and C++ are mixed/matched like above, the C source files also
need to be compiled with (1) -frtti to ensure type information is
available; and (2) -fexceptions to ensure exceptions pass correctly
through functions in C object files.

It may be better for libtools to provide both lt-cryptest.cpp and
lt-cryptestcwd.cpp in C++ projects so the mixing and matching does not
occur. That is, the libtool provided files will get the correct
CXXFLAGS by default.

It may be worth mentioning: we don't use/set CFLAGS; libtool needs to
get the project flags through CXXFLAGS in this case.

Jeff