Error compiling with g++ 3.4.4

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JR

    Error compiling with g++ 3.4.4

    The code below compiles and runs perfectly in Windows XP Pro, Using MS
    VS 2005.
    If I compile with g++ (cygwin) using the following command line:
    g++ -pedantic -Weffc++ -Wall -Wctor-dtor-privacy -Wold-style-cast -
    Woverloaded-virtual -o kk kk.cpp

    it displays the following errors:
    kk.cpp: In function `void Burp(std::ostre am&,
    std::vector<std ::vector<T, std::allocator< _CharT,
    std::allocator< std::vector<T, std::allocator< _CharT &)':
    kk.cpp:15: error: expected `;' before "ite"
    kk.cpp:15: error: `ite' undeclared (first use this function)
    kk.cpp:15: error: (Each undeclared identifier is reported only once
    for each function it appears in.)

    Any help is appreciated, Thanks.

    CODE:

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <stdexcept>
    #include <iterator>

    using namespace std;

    template <typename T>
    void Burp(ostream& os, vector< vector<T& vec)
    {
    os << "Our vector of vectors" << endl;
    for(vector< vector<T::itera tor ite = vec.begin(); ite!=
    vec.end();ite++ )
    {
    copy((*ite).beg in(), (*ite).end(), ostream_iterato r<T>(os, " "));
    os << endl;
    }
    os << "/Our vector of vectors" << endl;
    }

  • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

    #2
    Re: Error compiling with g++ 3.4.4

    On 2008-10-18 21:48, JR wrote:
    The code below compiles and runs perfectly in Windows XP Pro, Using MS
    VS 2005.
    If I compile with g++ (cygwin) using the following command line:
    g++ -pedantic -Weffc++ -Wall -Wctor-dtor-privacy -Wold-style-cast -
    Woverloaded-virtual -o kk kk.cpp
    >
    it displays the following errors:
    kk.cpp: In function `void Burp(std::ostre am&,
    std::vector<std ::vector<T, std::allocator< _CharT,
    std::allocator< std::vector<T, std::allocator< _CharT &)':
    kk.cpp:15: error: expected `;' before "ite"
    kk.cpp:15: error: `ite' undeclared (first use this function)
    kk.cpp:15: error: (Each undeclared identifier is reported only once
    for each function it appears in.)
    >
    Any help is appreciated, Thanks.
    >
    CODE:
    >
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <stdexcept>
    #include <iterator>
    >
    using namespace std;
    >
    template <typename T>
    void Burp(ostream& os, vector< vector<T& vec)
    {
    os << "Our vector of vectors" << endl;
    for(vector< vector<T::itera tor ite = vec.begin(); ite!=
    I can't see anything wrong on the 15th line (the above is the 13th) but
    try using
    for (typename vector< vector<T::itera tor ite = ...

    --
    Erik Wikström

    Comment

    • JR

      #3
      Re: Error compiling with g++ 3.4.4

      On Oct 18, 1:05 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
      On 2008-10-18 21:48, JR wrote:
      >
      >
      >
      The code below compiles and runs perfectly in Windows XP Pro, Using MS
      VS 2005.
      If I compile with g++ (cygwin) using the following command line:
       g++ -pedantic -Weffc++ -Wall -Wctor-dtor-privacy  -Wold-style-cast-
      Woverloaded-virtual -o kk kk.cpp
      >
      it displays the following errors:
      kk.cpp: In function `void Burp(std::ostre am&,
      std::vector<std ::vector<T, std::allocator< _CharT,
      std::allocator< std::vector<T, std::allocator< _CharT &)':
      kk.cpp:15: error: expected `;' before "ite"
      kk.cpp:15: error: `ite' undeclared (first use this function)
      kk.cpp:15: error: (Each undeclared identifier is reported only once
      for each function it appears in.)
      >
      Any help is appreciated, Thanks.
      >
      CODE:
      >
      #include <iostream>
      #include <vector>
      #include <algorithm>
      #include <stdexcept>
      #include <iterator>
      >
      using namespace std;
      >
      template <typename T>
      void Burp(ostream& os, vector< vector<T& vec)
      {
         os << "Our vector of vectors" << endl;
         for(vector< vector<T::itera tor ite = vec.begin(); ite!=
      >
      I can't see anything wrong on the 15th line (the above is the 13th) but
      try using
        for (typename vector< vector<T::itera tor ite = ...
      >
      --
      Erik Wikström
      Hi Erik, and many thanks for your input.

      Two things:

      - How did you figure out that by adding "typename" the error would
      go?...by the way the error message is not appearing anymore...
      -...however, now I am getting the following error (it looks like it
      came from a deeper part of the compiling process):
      $ g++ -Weffc++ -Wall -Wctor-dtor-privacy -Wold-style-cast -
      Woverloaded-virtual -o kk kk.cpp
      /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(lib cmain.o):
      (.text+0xab): undefined reference to `_WinMain@16'
      collect2: ld returned 1 exit status

      Does anybody know if the compiler g++ 3.4.4 is broken?

      Thanks again in advance. JR

      Comment

      • peter koch

        #4
        Re: Error compiling with g++ 3.4.4

        On 18 Okt., 22:51, JR <mr.riv...@yaho o.comwrote:
        On Oct 18, 1:05 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
        >
        >
        >
        >
        >
        On 2008-10-18 21:48, JR wrote:
        >
        The code below compiles and runs perfectly in Windows XP Pro, Using MS
        VS 2005.
        If I compile with g++ (cygwin) using the following command line:
         g++ -pedantic -Weffc++ -Wall -Wctor-dtor-privacy  -Wold-style-cast -
        Woverloaded-virtual -o kk kk.cpp
        >
        it displays the following errors:
        kk.cpp: In function `void Burp(std::ostre am&,
        std::vector<std ::vector<T, std::allocator< _CharT,
        std::allocator< std::vector<T, std::allocator< _CharT &)':
        kk.cpp:15: error: expected `;' before "ite"
        kk.cpp:15: error: `ite' undeclared (first use this function)
        kk.cpp:15: error: (Each undeclared identifier is reported only once
        for each function it appears in.)
        >
        Any help is appreciated, Thanks.
        >
        CODE:
        >
        #include <iostream>
        #include <vector>
        #include <algorithm>
        #include <stdexcept>
        #include <iterator>
        >
        using namespace std;
        >
        template <typename T>
        void Burp(ostream& os, vector< vector<T& vec)
        {
           os << "Our vector of vectors" << endl;
           for(vector< vector<T::itera tor ite = vec.begin(); ite!=
        >
        I can't see anything wrong on the 15th line (the above is the 13th) but
        try using
          for (typename vector< vector<T::itera tor ite = ...
        >
        --
        Erik Wikström
        >
        Hi Erik, and many thanks for your input.
        >
        Two things:
        >
        - How did you figure out that by adding "typename" the error would
        go?...by the way the error message is not appearing anymore...
        Because it is required by the standard. So it is Microsofts compiler
        that is broken in this respect, not gcc.
        -...however, now I am getting the following error (it looks like it
        came from a deeper part of the compiling process):
        $ g++  -Weffc++ -Wall -Wctor-dtor-privacy  -Wold-style-cast -
        Woverloaded-virtual -o kk kk.cpp
        /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(lib cmain.o):
        (.text+0xab): undefined reference to `_WinMain@16'
        collect2: ld returned 1 exit status
        This is a linker error. You are more likely to get help in a gcc
        newsgroup, but most likely you forgot to include a library.
        >
        Does anybody know if the compiler g++ 3.4.4 is broken?
        Yes it is - in the strictest sense of the word. But not here.

        /Peter

        Comment

        • JR

          #5
          Re: Error compiling with g++ 3.4.4

          On Oct 18, 1:51 pm, JR <mr.riv...@yaho o.comwrote:
          On Oct 18, 1:05 pm, Erik Wikström <Erik-wikst...@telia. comwrote:
          >
          >
          >
          On 2008-10-18 21:48, JR wrote:
          >
          The code below compiles and runs perfectly in Windows XP Pro, Using MS
          VS 2005.
          If I compile with g++ (cygwin) using the following command line:
           g++ -pedantic -Weffc++ -Wall -Wctor-dtor-privacy  -Wold-style-cast -
          Woverloaded-virtual -o kk kk.cpp
          >
          it displays the following errors:
          kk.cpp: In function `void Burp(std::ostre am&,
          std::vector<std ::vector<T, std::allocator< _CharT,
          std::allocator< std::vector<T, std::allocator< _CharT &)':
          kk.cpp:15: error: expected `;' before "ite"
          kk.cpp:15: error: `ite' undeclared (first use this function)
          kk.cpp:15: error: (Each undeclared identifier is reported only once
          for each function it appears in.)
          >
          Any help is appreciated, Thanks.
          >
          CODE:
          >
          #include <iostream>
          #include <vector>
          #include <algorithm>
          #include <stdexcept>
          #include <iterator>
          >
          using namespace std;
          >
          template <typename T>
          void Burp(ostream& os, vector< vector<T& vec)
          {
             os << "Our vector of vectors" << endl;
             for(vector< vector<T::itera tor ite = vec.begin(); ite!=
          >
          I can't see anything wrong on the 15th line (the above is the 13th) but
          try using
            for (typename vector< vector<T::itera tor ite = ...
          >
          --
          Erik Wikström
          >
          Hi Erik, and many thanks for your input.
          >
          Two things:
          >
          - How did you figure out that by adding "typename" the error would
          go?...by the way the error message is not appearing anymore...
          -...however, now I am getting the following error (it looks like it
          came from a deeper part of the compiling process):
          $ g++  -Weffc++ -Wall -Wctor-dtor-privacy  -Wold-style-cast -
          Woverloaded-virtual -o kk kk.cpp
          /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(lib cmain.o):
          (.text+0xab): undefined reference to `_WinMain@16'
          collect2: ld returned 1 exit status
          >
          Does anybody know if the compiler g++ 3.4.4 is broken?
          >
          Thanks again in advance. JR
          Hi,

          I resolved this problem by going to the mail archive of the cygwin
          mailing list for the Cygwin project, posting:

          Based on the command line for the compiling, I tried the following and
          it seemd to have worked:

          g++ -mno-cygwin -Weffc++ -Wall -Wctor-dtor-privacy -Wold-style-cast -
          Woverloaded-virtual -o kk kk.cpp

          I also utilized Erik W's advice by addding a typename before the
          instantiation of the iterator.

          Thanks Erik W!

          JR

          CODE: kk.cpp

          #include <iostream>
          #include <vector>
          #include <algorithm>
          #include <stdexcept>
          #include <iterator>

          using namespace std;

          template <typename T>
          void Burp(ostream& os, vector< vector<T& vec)
          {
          os << "Our vector of vectors" << endl;
          for(typename vector< vector<T::itera tor ite = vec.begin();
          ite!= vec.end();ite++ )
          {
          copy((*ite).beg in(), (*ite).end(),
          ostream_iterato r<T>(os, " "));
          os << endl;
          }
          os << "/Our vector of vectors" << endl;
          }

          int main(int argc, char argv[])
          {
          return 0;
          }



          Comment

          • James Kanze

            #6
            Re: Error compiling with g++ 3.4.4

            On Oct 18, 11:12 pm, peter koch <peter.koch.lar ...@gmail.comwr ote:
            On 18 Okt., 22:51, JR <mr.riv...@yaho o.comwrote:
            - How did you figure out that by adding "typename" the error
            would go?...by the way the error message is not appearing
            anymore...
            Because it is required by the standard. So it is Microsofts
            compiler that is broken in this respect, not gcc.
            Or it's just supporting pre-standard code. Earlier
            implementations of templates didn't require typename here, and
            any good compiler will have an option allowing the code to
            compile even without it. (To be fair, depending on the internal
            structure of the compiler, this can be a very expensive option
            to implement.)
            -...however, now I am getting the following error (it looks like it
            came from a deeper part of the compiling process):
            $ g++  -Weffc++ -Wall -Wctor-dtor-privacy  -Wold-style-cast -
            Woverloaded-virtual -o kk kk.cpp
            /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(lib cmain.o):
            (.text+0xab): undefined reference to `_WinMain@16'
            collect2: ld returned 1 exit status
            This is a linker error. You are more likely to get help in a gcc
            newsgroup, but most likely you forgot to include a library.
            With a name like _WinMain, I'd guess that he's trying to compile
            Microsoft specific code on a non-Microsoft platform.

            --
            James Kanze (GABI Software) email:james.kan ze@gmail.com
            Conseils en informatique orientée objet/
            Beratung in objektorientier ter Datenverarbeitu ng
            9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

            Comment

            • Hendrik Schober

              #7
              Re: Error compiling with g++ 3.4.4

              James Kanze wrote:
              On Oct 18, 11:12 pm, peter koch <peter.koch.lar ...@gmail.comwr ote:
              >On 18 Okt., 22:51, JR <mr.riv...@yaho o.comwrote:
              >
              >>- How did you figure out that by adding "typename" the error
              >>would go?...by the way the error message is not appearing
              >>anymore...
              >
              >Because it is required by the standard. So it is Microsofts
              >compiler that is broken in this respect, not gcc.
              >
              Or it's just supporting pre-standard code. Earlier
              implementations of templates didn't require typename here, and
              any good compiler will have an option allowing the code to
              compile even without it. (To be fair, depending on the internal
              structure of the compiler, this can be a very expensive option
              to implement.)
              VC, however, simply doesn't have two-phase lookup, so it has to
              "guess" if a 'typename' would have been required /after/ the
              template is instantiated. (At least that's my theory how it works.)
              The lack of two-phase lookup is /really/ annoying and makes VC
              almost unsuitable for any more serious work on template-heavy
              library code.
              (Just as a test, this
              template< typename T >
              void f() {blarxl}

              int main() {
              return 0;
              }
              indeed compiles fine using VC.)
              [...]
              Schobi

              Comment

              Working...