-11

I am getting this error while building a software (ns3) using waf

In file included from ../src/internet-stack/mp-tcp-typedefs.cc:6:
../src/internet-stack/mp-tcp-typedefs.h:151: error: ISO C++ forbids declaration of ‘multiset’ with no type
../src/internet-stack/mp-tcp-typedefs.h:151: error: expected ‘;’ before ‘<’ token
In file included from ../src/internet-stack/mp-tcp-socket-impl.cc:17:
../src/internet-stack/mp-tcp-typedefs.h:151: error: ISO C++ forbids declaration of ‘multiset’ with no type
../src/internet-stack/mp-tcp-typedefs.h:151: error: expected ‘;’ before ‘<’ token

I searched for the error and the solutions say that probably I am missing a using namespace std or #include <set> in my C++ code, but my code is not missing those. The file where the error originates [mp-tcp-typedefs.h] is here (Line 151 has the error).

I tried resolving the error but still, I Am getting those for a long time now.

My gcc/g++ version is g++ (Ubuntu/Linaro 4.4.7-8ubuntu1) 4.4.7.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Fernando
  • 13
  • 5
  • Make sure that your .h file is what has `#include `. – Daniel Aug 07 '15 at 16:10
  • @Daniel yes, the .h file is the one I posted, it has #include . – Fernando Aug 07 '15 at 16:10
  • That's the flaw in linking to your code. you should include the relevant code in the question itself. – Daniel Aug 07 '15 at 16:12
  • 2
    Please try to use `std::multiset` to make sure this isn't a weird form of a name lookup issue. If you can, please try another compiler. The one you're currently using seems to run into some kind of syntax misinterpretation (probably caused by a problem in your source code **before** line 151). Another compiler might have better diagnostics. – dyp Aug 07 '15 at 16:12
  • @dyp I tried using that, no benefit. Again errors get thrown + new errors. – Fernando Aug 07 '15 at 16:13
  • @Daniel The code was perhaps too big so I linked. – Fernando Aug 07 '15 at 16:14
  • If the errors are different, this might help! Please show them, if they're different. – dyp Aug 07 '15 at 16:14
  • @dyp sorry, I checked again, the errors are actually the same. – Fernando Aug 07 '15 at 16:15
  • @dyp I have g++ (Ubuntu/Linaro 4.4.7-8ubuntu1) 4.4.7 version. Maybe this could be of any help ? – Fernando Aug 07 '15 at 16:17
  • @Fernando: That's a *really* old version. Look to see if your package manager has an update available to gcc 4.9.x – Ben Voigt Aug 07 '15 at 16:19
  • 1
    The issue is not caused by the code you've shown/linked: http://melpon.org/wandbox/permlink/bj0SKMgUoHoIKrP8 So it must be caused by the headers, or by the the combination of the headers. – dyp Aug 07 '15 at 16:20
  • @BenVoigt Yes, I understand, I am using code that requires that version, I had to specifically install that older version (with a lot of pain). I am using an implementation of 2011 (of a protocol) and there s no other implementation available. – Fernando Aug 07 '15 at 16:26
  • What kind of errors did you get when you tried with the latest compiler? Usually fixing the broken code is a better idea than excising the new language features from the good code. – Ben Voigt Aug 07 '15 at 17:58
  • Try just using Clang and see what errors it gives; they're usually slightly better than GCC. – kirbyfan64sos Aug 07 '15 at 22:42
  • 1
    This is the same as http://stackoverflow.com/questions/31887223/iso-c-forbids-declaration-of-multiset – adrian008 Aug 09 '15 at 22:29
  • The compiler isn't recognizing `multiset` as a type. While I'd expect another error or warning to be given (have you tried warn all?), it's possible one of the "ns3" headers is breaking STD's `multiset` in some unpredictable way. You could try moving the set include to after those and see if anything changes, and try `-Wall`. If a multiset were declared inside the `ns3` namespace in one of those, its scope would take precedence to the STD multiset. `-Wall` would give you this (as a shadowing warning). –  Aug 10 '15 at 02:08
  • @WilliamKappler I tried it , same errors. – Fernando Aug 10 '15 at 14:56
  • This question is currently being discussed on Meta: http://meta.stackoverflow.com/q/302538/2415822 – JAL Aug 17 '15 at 15:30

1 Answers1

1

You should not put using namespace std; in a header file:

Why is "using namespace std;" considered bad practice?

You can probably fix your code by moving your using namespace std; inside your own namespace changing this:

using namespace std;

namespace ns3 {

to this:

namespace ns3 {

using namespace std;

But better to remove the using namespace std; and qualify all your standard symbols with std:: or else declare them individually inside your own namespace.

namespace ns3 {

using std::string;
using std::list;
using std::multiset;
using std::queue;
Galik
  • 47,303
  • 4
  • 80
  • 117
  • Could you kindly suggest some readings so that I could try fixing the error ? – Fernando Aug 07 '15 at 22:39
  • @Fernando When I made these changes it fixed your error on my system. Perhaps you didn't get it right? Can you post your new code somewhere so I can take a look? – Galik Aug 07 '15 at 22:41
  • @Fernando There is no siubstitute for a good book. Here is a *recommended* list: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – Galik Aug 07 '15 at 22:41
  • yes thanks for the guidance but really is this some kind of esosteric error ? It's just a syntax error like, it can't compile, what could be so wrong ? – Fernando Aug 07 '15 at 22:52
  • @Fernando Just put `std::` in front of your declation on line `151` so its like this: `std::multiset measuredRTT;`. Do that for each of the *standard* containers you use. – Galik Aug 07 '15 at 22:59
  • thanks again but STill I get the same errors on the same line. – Fernando Aug 07 '15 at 23:05
  • 6
    **Stop!** Alter your question so that it presents a [complete, minimal testcase](http://stackoverflow.com/help/mcve). – Lightness Races in Orbit Aug 07 '15 at 23:41
  • @Galik with std:: i get an extra error error: invalid use of ‘::’ – Fernando Aug 07 '15 at 23:57
  • @Fernando Can you post your code somewhere so I can see what you did? – Galik Aug 08 '15 at 00:00