User forums > Using Code::Blocks

C::B removes original extension of precompiled header

<< < (2/3) > >>

osdt:

--- Quote from: p2rkw on April 02, 2013, 05:52:11 pm ---For example file "precompiled.hpp" is pre-compiled to "precompiled.h.gch", but gcc expected "precompiled.hpp.gch", see here: http://gcc.gnu.org/onlinedocs/gcc/Precompiled-Headers.html
I know that precompiled header extension is replaced with extension setted in Compiler->Other settings -> Advanced opts -> Others, but as you can read in gcc manual:

--- Quote ---The name searched for is the name specified in the #include with ‘.gch’ appended. If the precompiled header file can't be used, it is ignored.
--- End quote ---
There's no need to remove original extension, only postfix ".gch" should be added.
...

--- End quote ---
Just some comments because I've been running into the same issue some time ago.

1) gcc requires to append '.gch' to the original header filename.
2) the current C::B implementation replaces the original header extension with 'h.gch' (default), see [1]. This will work as long as the original header extension is '.h'
3) setting the global compiler option (Advanced Options) to something else, e.g 'hpp.gch' will require all projects to use '.hpp' as precompiled headers.
4) because of (1), the global option is useless anyway

Conclusion: C::B has to be fixed  ;D

- osdt

[1] sdk\projectfile.cpp::190

--- Code: ---            if (project->GetModeForPCH() == pchSourceFile)
                fname.Assign(relativeFilename);
            fname.SetExt(compiler->GetSwitches().PCHExtension);
--- End code ---

stahta01:
@p2rkw and osdt:

Do either of you compile Code::Blocks yourself?

I am a C Programmer, who builds CB for myself on Windows 7 32-bit.

I have created a patch that I am doing the minimal level of testing for CB under Windows.

It will take a while, since my PC is really slow because I am compiling wxWidgets trunk right now.

I did only a tiny bit of testing on this patch it needs much more testing before I could recommend it be applied to CB trunk.

Edit: Updated patch to make it work more like the 12.11 version of CB; it now errors out when doing PCH "in directory along side header".
Edit2: Turns out 2 of the PCH methods do NOT work (in the same folder at the same time) since the PCH filename is the same as the PCH foldername; please remember to delete the PCH from one method before testing another in the same folder.



--- Code: ---Index: src/sdk/projectfile.cpp
===================================================================
--- src/sdk/projectfile.cpp (revision 8942)
+++ src/sdk/projectfile.cpp (working copy)
@@ -186,9 +186,14 @@
         if (compiler && compiler->GetSwitches().supportsPCH)
         {
             // PCHs are always using the extended name mode (at least for GCC)
-            // the extension is set to "h.gch"
+            // the extension is set to "h.gch" for .h files.
             if (project->GetModeForPCH() == pchSourceFile)
                 fname.Assign(relativeFilename);
+            if (fname.HasExt())
+            {
+                // Make the current file ext. part of the filename
+                fname.SetName(fname.GetName() + _T('.') + fname.GetExt());
+            }
             fname.SetExt(compiler->GetSwitches().PCHExtension);
             m_ObjName = fname.GetFullPath();
         }
@@ -382,7 +387,7 @@
 
                 wxFileName fn(source_file_native);
                 object_file_native = fn.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR) +
-                                    fn.GetName() + _T('.') + compiler->GetSwitches().PCHExtension +
+                                    fn.GetName() + _T('.') + fn.GetExt() + _T('.') + compiler->GetSwitches().PCHExtension +
                                     wxFILE_SEP_PATH +
                                     new_gch;
                 object_file_flat_native = object_file_native;
Index: src/sdk/compiler.cpp
===================================================================
--- src/sdk/compiler.cpp (revision 8942)
+++ src/sdk/compiler.cpp (working copy)
@@ -65,7 +65,7 @@
     linkerNeedsLibExtension = false;
     linkerNeedsPathResolved = false;
     supportsPCH             = true;
-    PCHExtension            = _T("h.gch");
+    PCHExtension            = _T("gch");
     UseFlatObjects          = false;
     UseFullSourcePaths      = false;
     Use83Paths              = false;
Index: src/plugins/compilergcc/resources/compilers/options_gcc.xml
===================================================================
--- src/plugins/compilergcc/resources/compilers/options_gcc.xml (revision 8942)
+++ src/plugins/compilergcc/resources/compilers/options_gcc.xml (working copy)
@@ -35,7 +35,7 @@
     <Switch name="linkerNeedsLibPrefix"    value="false"/>
     <Switch name="linkerNeedsLibExtension" value="false"/>
     <Switch name="supportsPCH"             value="true"/>
-    <Switch name="PCHExtension"            value="h.gch"/>
+    <Switch name="PCHExtension"            value="gch"/>
     <Switch name="UseFullSourcePaths"      value="true"/>
 
     <!-- Summary of GCC options: http://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html -->
Index: src/plugins/compilergcc/resources/advanced_compiler_options.xrc
===================================================================
--- src/plugins/compilergcc/resources/advanced_compiler_options.xrc (revision 8942)
+++ src/plugins/compilergcc/resources/advanced_compiler_options.xrc (working copy)
@@ -599,7 +599,7 @@
  </object>
  <object class="sizeritem">
  <object class="wxStaticText" name="ID_STATICTEXT35">
- <label>PCH extension (e.g. h.gch)</label>
+ <label>PCH extension (e.g. gch)</label>
  </object>
  <flag>wxTOP|wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL</flag>
  <border>4</border>

--- End code ---

Tim S.

osdt:
@stahta01: Your patch should work fine. It's basically the same as my local workarround some month ago exept I've used "gch" instead of 'PCHExtension'. I'll test it the next days.

Additionally - if it remains variable - you'll have to make sure 'PCHExtension' does not hold any
old user-defined value like "hpp.gch" or whatever.

AFAIK, all gcc-based compilers needs the extension to be "gch", so it could be a constant ?

Maybe some dev will comment on this.

- osdt

Alpha:
I will take a look at this patch.  If someone has test projects to post, that would be helpful.

osdt:

--- Quote from: Alpha on April 16, 2013, 04:26:53 am ---I will take a look at this patch.  If someone has test projects to post, that would be helpful.

--- End quote ---
Thanks. I'll provide a test project tomorrow.

- osdt

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version