Cannot use typeid with -fno-rtti [SOLVED]



  • 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.



  • 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.



  • 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?!?



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



  • [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.



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



  • [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



  • 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.



  • 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)



  • Thanks I'll give it a try!



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.