Problems with GNU C++ compiler and template classes

I’m using a GNU C/C++ compiler for a work project. The particular compiler is newer than what I’ve used in the past, and it’s actually a cross compiler.

I’m having multiple problems getting it to work properly. So far, everything can be chalked up to (re)learning curve and :smack: moments, but I still can’t get the stupid thing to digest STL template classes. The particular problem I’m seeing is that I include <list>, but <iterator> starts flagging nonsensical syntax errors. FWIW, I haven’t included <iterator>.

When I used GNU C++ in an academic environment (native mode), I had 0 problems. Similarly, the code I’m working with now was originally written in Visual C++, and it compiled just fine there, too.

I’ve spent 2 days now combing the GCC MAN pages for anything related to compiler switches or other options to indicate use of template classes, and I’ve come up empty. Help?!?

Are you compiling using gcc or g++? There are subtle differences between the two which can cause problems compiling C++ code with gcc. I’m not sure if that can cause problems compiling <list>, though.

G++ is the command…

Hm. What kind of errors are you getting? Also, you don’t have any syntax errors immediately preceding #include <list>, do you?

Something like this:

#include <list>

Would cause a weird error to show up in some header file.

Posting the smallest compilable code fragment which exhibits the problem and the exact error messages you get from trying to compile it (both within

tags) is usually helpful, if only because when narrowing down the problem you can sometimes find out how to solve it.

Try reading the G++ Manual. For templates in particular, read this section. Templates can be nasty creatures to compile. I usually use the -frepo switch, but you need to understand what you’re code is trying to do to choose wisely.

Edit: Oh, if you do play around with the template options, be sure to delete all *.o and *.rpo files before recompiling. Your make file should have a clean option to do this easily.

Or along those lines, something in a previously included header might be conflicting with something in the <list> header.