-1

I tried to add # include <vector> to a NS2 simulator file but i'm facing problems. i'm getting this error (I've used another computer with g++ 4.6 rather than old g++ 4.4). why only including <vector> causes error?

`g++ -c -Wall -Wno-write-strings  -DTCP_DELAY_BIND_ALL -DNO_TK -DTCLCL_CLASSINSTVAR  -DNDEBUG -DLINUX_TCP_HEADER -DUSE_SHM -DHAVE_LIBTCLCL -DHAVE_TCLCL_H -DHAVE_LIBOTCL1_14 -DHAVE_OTCL_H -DHAVE_LIBTK8_5 -DHAVE_TK_H -DHAVE_LIBTCL8_5 -DHAVE_TCLINT_H -DHAVE_TCL_H  -DHAVE_CONFIG_H -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=std -DUSE_SINGLE_ADDRESS_SPACE -Drng_test  -I. -I. -I/home/ns235/ns-allinone-2.35/tclcl-1.20 -I/home/ns235/ns-allinone-2.35/otcl -I/home/ns235/ns-allinone-2.35/include -I/home/ns235/ns-allinone-2.35/include -I/home/ns235/ns-allinone-2.35/include -I/usr/include/pcap -I./tcp -I./sctp -I./common -I./link -I./queue -I./adc -I./apps -I./mac -I./mobile -I./trace -I./routing -I./tools -I./classifier -I./mcast -I./diffusion3/lib/main -I./diffusion3/lib -I./diffusion3/lib/nr -I./diffusion3/ns -I./diffusion3/filter_core -I./asim/ -I./qs -I./diffserv -I./satellite -I./wpan -o tcp/tcp-fack.o tcp/tcp-fack.cc
In file included from /usr/include/c++/4.6/vector:61:0,
             from tcp/tcp-fack.cc:28:
 /usr/include/c++/4.6/bits/stl_algobase.h: In function ‘const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = TracedInt]:
tcp/tcp-fack.cc:87:37:   instantiated from here
  /usr/include/c++/4.6/bits/stl_algobase.h:215:7: error: no match for ‘operator<’ in ‘__a  < __b’
 /usr/include/c++/4.6/bits/stl_algobase.h:215:7: note: candidates are:
 /usr/include/c++/4.6/bits/stl_algobase.h:215:7: note: operator<(int, int) <built-in>
 /usr/include/c++/4.6/bits/stl_algobase.h:215:7: note:   no known conversion for argument 2 from ‘const TracedInt’ to ‘int’
/usr/include/c++/4.6/bits/stl_pair.h:207:5: note: template<class _T1, class _T2> bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
 /usr/include/c++/4.6/bits/stl_iterator.h:291:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
 /usr/include/c++/4.6/bits/stl_iterator.h:341:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_IteratorL>&, const   std::reverse_iterator<_IteratorR>&)
 /usr/include/c++/4.6/bits/stl_vector.h:1290:5: note: template<class _Tp, class _Alloc>   bool std::operator<(const std::vector<_Tp, _Alloc>&, const std::vector<_Tp, _Alloc>&)
make: *** [tcp/tcp-fack.o] Error 1

here is a snippet of stl_algobase.h lines (197-218). Is using templete in tcp-fack.cc causing the error? (http://www.cs.rit.edu/usr/local/pub/swm/gcc-4.7.2/include/c++/4.7.2/bits/stl_algobase.h)

/**
*  @brief This does what you think it does.
*  @ingroup sorting_algorithms
*  @param  __a  A thing of arbitrary type.
*  @param  __b  Another thing of arbitrary type.
*  @return   The greater of the parameters.
*
*  This is the simple classic generic implementation.  It will work on
*  temporary expressions, since they are only evaluated once, unlike a
*  preprocessor macro.
*/

template<typename _Tp>
inline const _Tp&
max(const _Tp& __a, const _Tp& __b)
{
  // concept requirements
  __glibcxx_function_requires(_LessThanComparableConcept<_Tp>)
  //return  __a < __b ? __b : __a;
  if (__a < __b)
return __b;
  return __a;
}

below is a snippet of tcp-fack.cc.Here is the original file with line number https://github.com/hbatmit/ns2.35/blob/master/tcp/tcp-fack.cc ( I only added <vector> at line 28)

#ifndef lint
static const char rcsid[] =
"@(#) /home/ctk21/cvsroot//hssstcp/ns/ns-2.1b9/tcp/tcp-fack.cc,v 1.2 2002/08/12 10:43:58     ctk21 Exp (PSC)";
#endif

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <vector>   //line 28
#include "ip.h"
#include "tcp.h"
#include "flags.h"
#include "scoreboard.h"
#include "random.h"
#include "tcp-fack.h"
#include "template.h"

static class FackTcpClass : public TclClass {
public:
FackTcpClass() : TclClass("Agent/TCP/Fack") {}
TclObject* create(int, const char*const*) {
    return (new FackTcpAgent());
    }
 } class_fack;


/*
 * Process a dupack.
 */
void FackTcpAgent::oldack(Packet* pkt)
{
hdr_tcp *tcph = hdr_tcp::access(pkt);

last_ack_ = tcph->seqno();
highest_ack_ = last_ack_;
fack_ = max(fack_,highest_ack_);
/* 
 * There are conditions under which certain versions of TCP (e.g., tcp-fs)
 * retract maxseq_. The following line of code helps in those cases. For
 * versions of TCP, it is a NOP.
     */
maxseq_ = max(maxseq_, highest_ack_);// This is line 87
if (t_seqno_ < last_ack_ + 1)
    t_seqno_ = last_ack_ + 1; // This is line 89 
newtimer(pkt);
if (rtt_active_ && tcph->seqno() >= rtt_seq_) { 
    rtt_active_ = 0;
    t_backoff_ = 1;
}
/* with timestamp option */
double tao = Scheduler::instance().clock() - tcph->ts_echo();
rtt_update(tao);
if (ts_resetRTO_) {
    // From Andrei Gurtov
    // FACK has not been updated to make sure the ECN works
    //   correctly in this case - Sally.
    t_backoff_ = 1;
}
/* update average window */
awnd_ *= 1.0 - wnd_th_;
awnd_ += wnd_th_ * cwnd_;
/* if the connection is done, call finish() */
if ((highest_ack_ >= curseq_-1) && !closed_) {
    closed_ = 1;
    finish();
}
}

int FackTcpAgent::maxsack(Packet *pkt)
{
hdr_tcp *tcph = hdr_tcp::access(pkt);
int maxsack=-1, sack_index; 

for (sack_index=0; sack_index < tcph->sa_length(); sack_index++) {
    if (tcph->sa_right(sack_index) > maxsack)
        maxsack = tcph->sa_right(sack_index);
}
return (maxsack-1);
}

** I have replaced <vector> with <map> and it showed the following error **

g++ -c -Wall -Wno-write-strings  -DTCP_DELAY_BIND_ALL -DNO_TK -DTCLCL_CLASSINSTVAR  -DNDEBUG -DLINUX_TCP_HEADER -DUSE_SHM -DHAVE_LIBTCLCL -DHAVE_TCLCL_H -DHAVE_LIBOTCL1_14 -DHAVE_OTCL_H -DHAVE_LIBTK8_5 -DHAVE_TK_H -DHAVE_LIBTCL8_5 -DHAVE_TCLINT_H -DHAVE_TCL_H  -DHAVE_CONFIG_H -DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=std -DUSE_SINGLE_ADDRESS_SPACE -Drng_test  -I. -I. -I/home/ns235/ns-allinone-2.35/tclcl-1.20 -I/home/ns235/ns-allinone-2.35/otcl -I/home/ns235/ns-allinone-2.35/include -I/home/ns235/ns-allinone-2.35/include -I/home/ns235/ns-allinone-2.35/include -I/usr/include/pcap -I./tcp -I./sctp -I./common -I./link -I./queue -I./adc -I./apps -I./mac -I./mobile -I./trace -I./routing -I./tools -I./classifier -I./mcast -I./diffusion3/lib/main -I./diffusion3/lib -I./diffusion3/lib/nr -I./diffusion3/ns -I./diffusion3/filter_core -I./asim/ -I./qs -I./diffserv -I./satellite -I./wpan -o tcp/tcp-fack.o tcp/tcp-fack.cc
In file included from /usr/include/c++/4.6/bits/stl_tree.h:63:0,
             from /usr/include/c++/4.6/map:60,
             from tcp/tcp-fack.cc:28:
/usr/include/c++/4.6/bits/stl_algobase.h: In function ‘const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = TracedInt]’:
tcp/tcp-fack.cc:87:37:   instantiated from here
/usr/include/c++/4.6/bits/stl_algobase.h:215:7: error: no match for ‘operator<’ in ‘__a < __b’
/usr/include/c++/4.6/bits/stl_algobase.h:215:7: note: candidates are:
/usr/include/c++/4.6/bits/stl_algobase.h:215:7: note: operator<(int, int) <built-in>
/usr/include/c++/4.6/bits/stl_algobase.h:215:7: note:   no known conversion for argument 2 from ‘const TracedInt’ to ‘int’
/usr/include/c++/4.6/bits/stl_pair.h:207:5: note: template<class _T1, class _T2> bool  std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)
/usr/include/c++/4.6/bits/stl_iterator.h:291:5: note: template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
/usr/include/c++/4.6/bits/stl_iterator.h:341:5: note: template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_IteratorL>&, const std::reverse_iterator<_IteratorR>&)
/usr/include/c++/4.6/bits/stl_tree.h:866:5: note: template<class _Key, class _Val, class _KeyOfValue, class _Compare, class _Alloc> bool std::operator<(const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&, const std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>&)
/usr/include/c++/4.6/bits/stl_map.h:899:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::map<_Key, _Tp, _Compare, _Alloc>&, const std::map<_Key, _Tp, _Compare, _Alloc>&)
/usr/include/c++/4.6/bits/stl_multimap.h:817:5: note: template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator<(const std::multimap<_Key, _Tp, _Compare, _Alloc>&, const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
make: *** [tcp/tcp-fack.o] Error 1
  • How about a snippet of the _relevant_ code responsible for the error. According to your error log that would be line 28 (and those around it) in `tcp-fack.cc`. – Captain Obvlious Dec 27 '13 at 01:56
  • Good that you have the code now, but it needs to be formatted properly so answerers can read it. It would also be helpful to have the line number mentioned in the error stated in a comment, since we don't get line numbers here. – Chris Hayes Dec 28 '13 at 03:37
  • this is the orignal file https://github.com/hbatmit/ns2.35/blob/master/tcp/tcp-fack.cc. I only added `` at line 28 – user1683302 Dec 28 '13 at 03:58
  • is it now formatted properly ? – user1683302 Dec 28 '13 at 04:51
  • is it possible that tcp-fack.cc has variables that has similar names in stl_algobase.h? – user1683302 Dec 28 '13 at 15:59
  • i think i found the error. The error is caused by `template.h` it has function that is called swap()? – user1683302 Dec 28 '13 at 18:32

1 Answers1

0

I found the solution; NS-2 template.h has swap() and max() functions. swap() is a member function of standard <vector>. and max() is a member function of standard stl_algorithm(). Also NS-2 god.h has a class called vector(). These NS-2 function were causing conflicts with <Vector> and <algorithm> libraries.

I changed the names of NS2 funtions and now everything works.

Thanks