Author Topic: Possible to not precompile headers?  (Read 4438 times)

davereid20

  • Guest
Possible to not precompile headers?
« on: January 19, 2006, 02:28:09 am »
I'm working on a project for college and I've just started out using Code::Blocks Studio and I've been impressed so far as to make it my standard C++ IDE. Recently, I've been creating a templated Stack/Queue ADT and it seems to be fine except that Code::Blocks precompiles my header files (*.h.gch) of the templated struct/class and the MinGW throws an error that ".objs\StackNode.h.gch: file not recognized: File format not recognized"

I've included the project in a zip file. I'm using MinGW 3.4.5 (Candidate). When compiled with the Microsoft Visual C++ 2003 Toolkit, it compiles and runs without problems.

[attachment deleted by admin]

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Possible to not precompile headers?
« Reply #1 on: January 19, 2006, 03:01:23 am »
In the project tree, right click on StackNode.h, select Properties and uncheck both "Compile file" and "Link file".

That done it compiles and links without problems (you don't need to compile that header file).

It's a shame only a few C++ compilers support exported templates, and g++ isn't one of those. Including a cpp file looks ugly :(

davereid20

  • Guest
Re: Possible to not precompile headers?
« Reply #2 on: January 19, 2006, 04:49:19 am »
Ceniza,

Thanks for the help. I've got it to work. I guess I learned to use templates by declaring functions in the header file, put an #include "[classname].cpp" at the bottom of the header, and not put an #include "[classname].h" at the top of the .cpp file.  Guess I can just continue doing it the same as non-templated classes.  If anything else comes up, I'll post here.

davereid20

  • Guest
Re: Possible to not precompile headers?
« Reply #3 on: January 19, 2006, 06:32:59 am »
Would there ever be an option to not precombile headers or will that not be ever useful?

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: Possible to not precompile headers?
« Reply #4 on: January 19, 2006, 07:31:00 am »
Well, if you want to do something more with a header than just including it, it's precompile it. If you are considering to compile it, think again if it should really be a header or a source file.

At least here adding a header file to a project won't check it for precompilation.

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Possible to not precompile headers?
« Reply #5 on: January 19, 2006, 12:02:49 pm »
It's a shame only a few C++ compilers support exported templates, and g++ isn't one of those. Including a cpp file looks ugly :(

I have this problem sometimes ago when working with templates. Instead of including the cpp file (really ugly :(), you can implement all in the .h file and include it (better IMHO :)). When I asked an expert he told me:

Quote
Templates are not compilable, they have to be instantiated and the instances will be compiled (in the main source).

Anyway, I got the same problems with GCC 3.4.4 and MS Visual Studio .NET 2003.

Michael