2

I am working on an Autools front-end for a C++ library. It looks like Libtool is adding C source files to the project and its causing a fair amount of trouble on some platforms. We think its causing unexplained crashes like Message “During startup program terminated with signal SIGKILL” from GDB.

The C source files cause trouble for several reasons. First, we only query CXXFLAGS and set AM_CXXFLAGS; and we don't do anything with CFLAGS or AM_CFLAGS. Second, C files need additional options in a C++ project, like -frtti and -fexceptions under GCC and options like -qrtti under IBM XL C/C++ compiler. Its not clear to me if libtool is adding the necessary options. Third, the C source files added by Libtool need additional Posix options on platforms that use Newlib, like Cygwin and MSYS. Our source files don't need the options.

I'd like to force Libtool to use C++ instead of C but I have not been able to locate an option or method to do so. I think the easiest path would be for Libtool to use lt-<some file>.cpp and CXXFLAGS rather than lt-<some file>.c and CFLAGS but I can't figure out how to do it.

How do we tell Libtool to use C++ and not C?


A related problem is How to disable C compiler in C++ Autotools project, but it only ask to use the C++ compiler for feature testing.

jww
  • 97,681
  • 90
  • 411
  • 885
  • If `libtool` is really adding C source files then they ought to be compiled via a C compiler. C and C++ are distinct languages, each with features that the other lacks. It is not, in general, safe to assume that you can compile C source successfully with a C++ compiler, and if you do succeed in that, it is not safe to assume that the resulting binary has semantics equivalent to those that one built from the same source by a C compiler would have. – John Bollinger Nov 15 '17 at 22:22
  • But this whole thing is surprising to me. Is it related to LTDL? I can't think of any other reason why `libtool` would need to add any runtime code to a project. – John Bollinger Nov 15 '17 at 22:24
  • @JohnBollinger - I think Libtool adds some sort of wrapper program that calls the real program (or some component in libtool does it). I only realized it when the wrapper failed to compile. See, for example, [C++ compiler, Newlib and "implicit declaration of function '_spawnv'"](https://lists.gnu.org/archive/html/bug-libtool/2017-11/msg00002.html) on the libtool mailing list. – jww Nov 15 '17 at 22:25
  • Not in my builds for Linux, OS X, or MinGW. But again, I could believe that it might happen if LTDL is involved to support dynamically loadable modules on systems where that is tricky. – John Bollinger Nov 15 '17 at 22:28
  • Anyway, have you considered setting the needed flags in `AM_CFLAGS`? That shouldn't affect any of your C++ compilations, but it ought to be applied to C sources involved in any target that doesn't define its own C flags. – John Bollinger Nov 15 '17 at 22:31

1 Answers1

0

You could add the C compiler options you mention to the CFLAGS env var before compilation. Do you see any reasons why this would not work?

Gunee
  • 431
  • 3
  • 16