Thread: GCC Compiler question about #pragma implementation

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    4,183

    GCC Compiler question about #pragma implementation

    I hope this question is valid on this site and in this sub-forum.

    I am fixing some C++ Compiler build time issues and I have found that
    MinGW GCC does NOT support including PCH headers after "#pragma implementation". What does "#pragma implementation" do? And, will it still work if I move it after all the includes?

    Edit: PCH means pre-compiled headers.

    Tim S.

    Code:
    #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
        #pragma implementation "wxchart.cpp"
        #pragma interface "wxchart.cpp"
    #endif
    
    // For compilers that support precompilation, includes "wx.h".
    #include <wx/wxprec.h>
    
    #ifdef __BORLANDC__
        #pragma hdrstop
    #endif
    Last edited by stahta01; 02-11-2014 at 01:08 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    [Edit]
    I think this maybe should be moved to "tech" because this isn't actually specific to C++; the issue is born of a how a few compilers used to do things.
    [/Edit]

    You should just throw a `-DNO_GCC_PRAGMA' at your build process.

    [Edit]
    If that "wx" is "wxWidgets", you should also update your code; I've just looked, and `-DNO_GCC_PRAGMA' is default in my copy.
    [/Edit]

    I've literally just now learned of "#pragma implementation", but from what I understand, these directives are never needed with standard conforming C++.

    Way back before C++ was standardized compilers were trying to figure out how to support templates without violating the "one definition rule" yet allowing "exported templates". The directives in question are seemingly part of that resolution, but because the linker model has sufficiently changed and "exported templates" never really worked--as far as I know only two compilers ever got it right--such methods are no longer relevant.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Thank you for that answer; I thought it was more related to C++ than NOT C++.

    I have to now figure out if NO_GCC_PRAGMA is positively safe to do.
    Looks like that is not a great solution sometimes the code does not have the "!defined(NO_GCC_PRAGMA)" part.
    But, it still might be good solution.
    At least, I now know it is related to C++ Templates.

    The code is using wxWidgets; but, is NOT part of wxWidgets.

    Tim S.
    Last edited by stahta01; 02-11-2014 at 01:34 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  4. #4
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    If you have the option, compile and link the application with `NO_GCC_PRAGMA'.

    If you get the compiler error about "missing definition", the code incorrectly expects a version of "exported templates" that doesn't practically exist.

    If you get the compiler error about "duplicate definition", the code does incorrectly rely on the "pragma"--so not standard C++.

    If you get a linker error about "duplicate definition", the source incorrectly links "exported templates" explicitly within multiple translation units.

    That is, obviously, far and away from being the only possible errors, but the hope is that the code is standard regardless of age, libraries used. If you successfully compiled and link, you can at least comment the "pragma" so you can use `-E' and `-E -dM' to find any unrelated problems with defining the macro.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Thank you for the help; I have decided to try building with "NO_GCC_PRAGMA"; and, if that works remove the #pragma implementation and interface code.

    I did some grepping and wxWidgets 2.6.3 has this all over the place while its only in one place in wxWidgets 2.8.0.

    Tim S.
    Last edited by stahta01; 02-11-2014 at 02:06 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about #pragma once
    By tjpanda in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2008, 09:10 AM
  2. implementation question
    By zmaker5 in forum C Programming
    Replies: 10
    Last Post: 08-04-2007, 12:35 PM
  3. Tetris implementation question
    By thesame in forum Game Programming
    Replies: 4
    Last Post: 10-23-2006, 05:37 AM
  4. Compiler design and implementation: token parsing
    By Unregistered in forum C Programming
    Replies: 15
    Last Post: 04-30-2002, 01:12 PM
  5. ObjModLib Compiler for pragma comment.
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 12-26-2001, 02:55 PM