Score:0

G++ Causing Struct Redefinition Errors in "type_traits.h" and Other Include Files

kp flag

I have "been tasked" with trying to build old software (VERY old software, in fact, not compiled since 2014) on our newer platform, specifically using g++ 9.4.0 in Ubuntu 20.04. While doing so, I have encountered a number of errors, all of them occurring inside some of include files from "/usr/include/c++/9". The offending files are type_traits.h, bits/allocator.h, bits/basic_string.h, and bits/alloc_traits.h.

The build output looks like this:

make -C /home/schudall/TDWR_Appl_LocalUB/csci04/csc25
make[1]: Entering directory '/home/schudall/TDWR_Appl_LocalUB/csci04/csc25'
/usr/bin/g++ -c -I/home/schudall/TDWR_Appl_LocalUB/csci04/csc20 -I/home/schudall/TDWR_Appl_LocalUB/csci04/csc25  -Dvolatile= -O2 -Di586 -Wall -Wno-unused -DWX_MULTITHREADED -D_REENTRANT WxBase.C -o LINUX/WxBase.o
In file included from /usr/include/c++/9/bits/move.h:55,
                 from /usr/include/c++/9/bits/nested_exception.h:40,
                 from /usr/include/c++/9/exception:144,
                 from /usr/include/c++/9/ios:39,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from WxBase.C:33:
/usr/include/c++/9/type_traits:506:12: error: redefinition of ‘struct std::is_function<_Res(_ArgTypes ...)>’
  506 |     struct is_function<_Res(_ArgTypes...) volatile _GLIBCXX_NOEXCEPT_QUAL>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/usr/include/c++/9/type_traits:458:12: note: previous definition of ‘struct std::is_function<_Res(_ArgTypes ...)>’
  458 |     struct is_function<_Res(_ArgTypes...) _GLIBCXX_NOEXCEPT_QUAL>
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is just one example of a number of other, similar errors being called out.

Point of disclosure: While I have some years' experience in programming C++, most of my experience has been in taking older code and transferring it to our systems. My C++ training dates to about 20-25 years ago (pre ANSI???). Also, I am newer to the Ubuntu environment.

With all that said, it looks like maybe I am not including something that these files need, or not passing in proper arguments to the compiler, or perhaps I have not installed all needed libraries to build on this device. OR the code is so deprecated, but I would not know where to begin cleaning things up with these errors. Reading the man pages has not helped :(

What I would like to ask is, if anyone with a deeper (and more up-to-date) base of experience than me can point me in the right direction, and give me some idea as to what I need to do to solve these issues? Thank you in advance!

cn flag
Ray
I've found that when you go to a newer version of C++, you sometimes get a more restrictive compiler because the standard has become more restrictive. i.e., it now doesn't allow what was previously allowed, which in the end helps the programmer. Ubuntu 20.04 seems to have g++ as far back as version 7 (see [here](https://packages.ubuntu.com/focal/g++-7)). Try an older version and see if that works. If it does, move up from that and maybe you'll find out which `gcc` breaks it. The modify the code as necessary. Instead of using a `Makefile`, find one file and focus on that first.
hr flag
It's the `-Dvolatile=` preprocessor directive that's causing that particular error, I think
hr flag
... so perhaps `make CXXFLAGS=-Uvolatile -C /home/schudall/TDWR_Appl_LocalUB/csci04/csc25` or `make CPPFLAGS=-Uvolatile -C /home/schudall/TDWR_Appl_LocalUB/csci04/csc25` would be worth a try (hard to guess without seeing the Makefile)
RonFAA avatar
kp flag
Thank you both for your responses. Will be trying this over the next few days and will get back to you with results!
RonFAA avatar
kp flag
Both of your suggestions were implemented and have apparently solved much of the problems encountered. Also dealing with namespace issues related to many of the iostream definitions, but that will simply require some "elbow grease" to clean up the old code and bring it up to date. Thank you both for your help.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.