Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot use typeid with -fno-rtti [SOLVED]
QtWS25 Last Chance

Cannot use typeid with -fno-rtti [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 11.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Seraph
    wrote on 24 Oct 2012, 16:11 last edited by
    #1

    Hi folks,

    I'm using mingw4.0.4 with QT4.8.3 and Creator 2.5.2.
    I just want to compile the following simple line of code in a default hello world console program:

    @cout<<typeid(a).name()<<endl;@

    The compiler brings the following error:

    'cannot use typeid with -fno-rtti'

    Any idea how to fix this? Where can i add/remove such compiler parameters? I only found the qmake arguments!

    Big thanks in advance.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 24 Oct 2012, 22:15 last edited by
      #2

      typeid is only available with runtime type information (rtti).
      AFAIK, Qt by default is compiled without rtti. You can add compile parameters in the qmake file so your code has rtti but then take care to not try it on Qt classes.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Seraph
        wrote on 25 Oct 2012, 10:03 last edited by
        #3

        What exact parameter do I have to add to have rtti?
        OK - I found it in the build directory: Makefile.XXX CXXFLAGS

        CXXFLAGS = -O2 -Wall -Wextra -fno-exceptions -fno-rtti $(DEFINES)

        The Problem is, that when I rebuild or clean the projects, these makefiles will be recreated with -fno-rtti!!! Grrrrr
        Isn't it somehow possible to set this up in the project itself? When I just check in the .pro files and the source files! So everybody who is working on the projects has to change it himself? There must be a more common way?!?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on 25 Oct 2012, 10:42 last edited by
          #4

          I only include this, and works:
          #include <typeinfo>

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Seraph
            wrote on 25 Oct 2012, 11:51 last edited by
            #5

            [quote author="broadpeak" date="1351161772"]I only include this, and works:
            #include <typeinfo>[/quote]

            With MinGW under Windows? Im working on the same projects under Ubuntu using gcc with no problem, too.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              broadpeak
              wrote on 25 Oct 2012, 12:19 last edited by
              #6

              I used it under Windows but with MinGW. (QtSDK 1.2.1)

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Seraph
                wrote on 26 Oct 2012, 07:35 last edited by
                #7

                [quote author="broadpeak" date="1351167587"]I used it under Windows but with MinGW. (QtSDK 1.2.1)[/quote]

                Hmm... That is a very old version don't u think!?

                Anyways, it's not working by default on any of my workstations using MinGW!
                So my question still is: Is it somehow possible to set CXXFLAGS via .pro file or creator settings?
                I don't want all developers to change their global configs just to compile this project!
                hmm....

                Thanks in advice

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  broadpeak
                  wrote on 26 Oct 2012, 07:52 last edited by
                  #8

                  My Qt is:
                  g++ = 4.4.0
                  qt = 4.8.1
                  I think these are not so old versions...
                  And in my .pro file there is nothing about the RTTI.
                  I only use the above mentioned include file.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    broadpeak
                    wrote on 26 Oct 2012, 13:30 last edited by
                    #9

                    Hahaha :)
                    I run into the same issue :)

                    Solution:

                    in .pro file:
                    CONFIG += rtti (this is enough in theory)
                    or
                    CXXFLAGS = -g -Wall -Wextra -fno-exceptions -fno-rtti $(DEFINES)

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Seraph
                      wrote on 26 Oct 2012, 14:24 last edited by
                      #10

                      Thanks I'll give it a try!

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Seraph
                        wrote on 8 Nov 2012, 17:12 last edited by
                        #11

                        Hey fellas,

                        Sorry i forgot to post my result here:

                        The following solved the problem (like broadpeak said! Thank you!)

                        In the .pro file just add the line
                        @CONFIG += rtti@

                        That's it.

                        See u guys around

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved