News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

C::B removes original extension of precompiled header

Started by p2rkw, April 02, 2013, 05:52:11 PM

Previous topic - Next topic

p2rkw

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:
QuoteThe 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.
There's no need to remove original extension, only postfix ".gch" should be added.

PS. I found second usability bug: changes made in Compiler->Other settings -> Advanced opts -> Others enter into force not when you click "ok", but when you reload project.

oBFusCATed

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:
QuoteThe 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.
There's no need to remove original extension, only postfix ".gch" should be added.
OS and version please.
Probably simple example project?

Quote from: p2rkw on April 02, 2013, 05:52:11 PM
PS. I found second usability bug: changes made in Compiler->Other settings -> Advanced opts -> Others enter into force not when you click "ok", but when you reload project.
Exact steps to reproduce?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

p2rkw

Fedora, svn rev 8926, project in attachment. As you can see in build log all.hpp was compiled twice, because gcc couldn't find all.hpp.gch.

Quote
Exact steps to reproduce?
Open test project, build it, then change for example Compiler->Other settings -> Advanced opts -> Others -> PCH extension and rebuild project. C::B will use old pch extension.

Jenna

The issue happens with extension h.gch and also with hpp.gch, and it does not matter what the real headers ending is, so it is either a compiler bug or the -H option does not work as expected and always show the included headers, even if they are included via pch.

p2rkw

Heres my build log when I rename all.hpp to all.h and set it as precompiled header:

Build started on: 05-04-2013 at 22:37.59
Build ended on: 05-04-2013 at 22:38.00
-------------- Build: debug in precompiled_test (compiler: GNU GCC Compiler)---------------
g++ -Wall -Winvalid-pch -H -g -Wextra -Wall -c /home/pawel/Pulpit/test/precompiled_test/all.h -o all.h.gch
/home/pawel/Pulpit/test/precompiled_test/all.h:1:9: warning: #pragma once in main file [enabled by default]
. /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iostream
.. /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/c++config.h
... /usr/include/bits/wordsize.h
... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/os_defines.h
.... /usr/include/features.h
..... /usr/include/sys/cdefs.h
...... /usr/include/bits/wordsize.h
..... /usr/include/gnu/stubs.h
...... /usr/include/bits/wordsize.h
...... /usr/include/gnu/stubs-64.h
... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/cpu_defines.h
.. /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ostream
... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ios
.... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/iosfwd
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stringfwd.h
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/postypes.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/cwchar
....... /usr/include/wchar.h
........ /usr/include/stdio.h
........ /usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/stdarg.h
........ /usr/include/bits/wchar.h
........ /usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/stddef.h
........ /usr/include/xlocale.h
.... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/exception
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/atomic_lockfree_defines.h
.... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/char_traits.h
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/functexcept.h
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/exception_defines.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/cpp_type_traits.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ext/type_traits.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ext/numeric_traits.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_pair.h
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/move.h
........ /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/concept_check.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_iterator_base_types.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_iterator_base_funcs.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_iterator.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/debug/debug.h
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/cwchar
...... /usr/include/wchar.h
.... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/localefwd.h
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/c++locale.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/clocale
....... /usr/include/locale.h
........ /usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/stddef.h
........ /usr/include/bits/locale.h
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/cctype
...... /usr/include/ctype.h
....... /usr/include/bits/types.h
........ /usr/include/bits/wordsize.h
........ /usr/include/bits/typesizes.h
....... /usr/include/endian.h
........ /usr/include/bits/endian.h
........ /usr/include/bits/byteswap.h
......... /usr/include/bits/wordsize.h
.... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ios_base.h
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ext/atomicity.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/gthr.h
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/gthr-default.h
........ /usr/include/pthread.h
......... /usr/include/sched.h
.......... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/stddef.h
.......... /usr/include/time.h
.......... /usr/include/bits/sched.h
......... /usr/include/time.h
.......... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/stddef.h
.......... /usr/include/bits/time.h
........... /usr/include/bits/timex.h
......... /usr/include/bits/pthreadtypes.h
.......... /usr/include/bits/wordsize.h
......... /usr/include/bits/setjmp.h
.......... /usr/include/bits/wordsize.h
......... /usr/include/bits/wordsize.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/atomic_word.h
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/string
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/allocator.h
........ /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/c++allocator.h
......... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/ext/new_allocator.h
.......... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/new
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream_insert.h
........ /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/cxxabi_forced.h
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/stl_function.h
........ /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/backward/binders.h
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/range_access.h
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.h
....... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/basic_string.tcc
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/locale_classes.tcc
.... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/streambuf
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/streambuf.tcc
.... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/basic_ios.h
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/locale_facets.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/cwctype
....... /usr/include/wctype.h
........ /usr/include/wchar.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/cctype
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/ctype_base.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/streambuf_iterator.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/ctype_inline.h
...... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/locale_facets.tcc
..... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/basic_ios.tcc
... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/ostream.tcc
.. /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/istream
... /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/bits/istream.tcc
Multiple include guards may be useful for:
/usr/include/bits/byteswap.h
/usr/include/bits/endian.h
/usr/include/bits/locale.h
/usr/include/bits/sched.h
/usr/include/bits/time.h
/usr/include/bits/typesizes.h
/usr/include/gnu/stubs-64.h
/usr/include/gnu/stubs.h
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/clocale
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/cwctype
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/ctype_base.h
/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../include/c++/4.7.2/x86_64-redhat-linux/bits/ctype_inline.h
g++ -Wall -Winvalid-pch -H -g -Wextra -Wall -c /home/pawel/Pulpit/test/precompiled_test/main.cpp -o obj/debug/main.cpp.o
! /home/pawel/Pulpit/test/precompiled_test/all.h.gch
/home/pawel/Pulpit/test/precompiled_test/main.cpp
g++ -o precompiled_test obj/debug/main.cpp.o
Output size is 17,41 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 1 warning(s) (0 minute(s), 1 second(s))

all.h was compiled only once.

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:
QuoteThe 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.
There's no need to remove original extension, only postfix ".gch" should be added.
...
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
            if (project->GetModeForPCH() == pchSourceFile)
                fname.Assign(relativeFilename);
            fname.SetExt(compiler->GetSwitches().PCHExtension);


stahta01

#6
@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.



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>


Tim S.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

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.
Thanks. I'll provide a test project tomorrow.

- osdt

Alpha


osdt

Quote from: Alpha on April 19, 2013, 04:10:01 PM
Committed (modified).  (Revision 9000 ;) !)
Thanks for the quick fix, works flawlessly.

- osdt

PS: HAL was involved?  ;D

Alpha