Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Build C::B against wx3.02 with gcc 5.2 under Windows
stahta01:
--- Quote from: ollydbg on October 06, 2015, 04:44:25 am ---Now, I did some test in codeblocks_wx30.cbp
1, I remove the "src\.objs30\include\sdk.h.gch", so the folder only contains "sdk_precomp.h.gch", note that the first one was create when we build the src target(codeblocks.exe), and the later one is generated when we build the sdk target(codeblocks.dll).
2, select the "sdk.h" from the project manager panel, and right click to open the "property" dialog, and uncheck the "compile file" option.
3, copy the build option from sdk to src, that is: remove the "BUILDING_PLUGIN", and add those:
--- Code: ---EXPORT_LIB
EXPORT_EVENTS
WXMAKINGDLL_SCI
--- End code ---
4, rebuild the target src(codeblocks.exe), and I see it build successfully, great! This means both the codeblocks.exe and codeblocks.dll now share the same pch file "sdk_precomp.h.gch".
I will see I can built any plugin dll later. :)
EDIT:
Good, with the same change to other C::B plugin target, I can also build them successfully, also the build C::B runs OK.
--- End quote ---
1. Did you make sure the warning "-Winvalid-pch" is set?
2. Is the include of the PCH the first include in the file?
3. Is the path to the PCH header include before the NON PCH version of the header.
Tim S.
ollydbg:
--- Quote from: stahta01 on October 06, 2015, 04:56:40 pm ---1. Did you make sure the warning "-Winvalid-pch" is set?
--- End quote ---
Yes, this option is on the project level.
--- Quote ---2. Is the include of the PCH the first include in the file?
3. Is the path to the PCH header include before the NON PCH version of the header.
--- End quote ---
I think I have made some mistakes, it looks like the "non pch version of the header file" is used here, but "-Winvalid-pch" never show a warning about this, I will look into it.
Thanks.
EDIT normally the plugins and the src target need the file named "sdk.h", since there is no such "sdk.h.gch", then the original header file is used instead. :(
ollydbg:
Hi, Tim, the problem can be solved.
I just read the document page: Precompiled Headers - Using the GNU Compiler Collection (GCC)
And this is what I did:
1, in my ".objs30\include" folder, I have two files
sdk_precomp.h.gch, this is the pch file generated when building the sdk target.
I create another one in this folder, named: sdk_precomp.h, and it has the contents:
--- Code: ---#error "non pch file is used!!!"
--- End code ---
So, if the original "sdk_precomp.h" is used, the compiler will show an error.
2, this is my modified "include\sdk.h"
--- Code: ---/*
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
* http://www.gnu.org/licenses/lgpl-3.0.html
*/
/** Code::Blocks SDK precompiled headers support for plugins.
* This is precompiled with -DBUILDING_PLUGIN
*/
#ifndef SDK_H
#define SDK_H
//#ifdef __WXMSW__
// #include "sdk_common.h"
//#else
// for non-windows platforms, one PCH is enough
#include "sdk_precomp.h"
//#endif
#endif // SDK_H
--- End code ---
Thus, I will let the "sdk.h" include "sdk_precomp.h".
3, simply do the previous two step doesn't solve the issue. As the document said:
--- Quote ---A precompiled header can't be used once the first C token is seen. You can have preprocessor directives before a precompiled header; you cannot include a precompiled header from inside another header.
--- End quote ---
The strange thing is: if I move the "sdk_precomp.h.gch" from the ".objs30/include" folder, and leave the dummy "sdk_precomp.h" in that folder, then rebuild a plugin, I see the build success. I think it should report an error from the dummy header.
--- Code: ----------------- Clean: Autosave in Code::Blocks wx3.0.x (compiler: GNU GCC Compiler)---------------
Cleaned "Code::Blocks wx3.0.x - Autosave"
-------------- Build: Autosave in Code::Blocks wx3.0.x (compiler: GNU GCC Compiler)---------------
[ 50.0%] g++.exe -Wall -g -pipe -mthreads -fmessage-length=0 -fexceptions -Winvalid-pch -Wno-deprecated-declarations -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DcbDEBUG -DCB_PRECOMP -DWX_PRECOMP -DwxUSE_UNICODE -DEXPORT_LIB -DEXPORT_EVENTS -DWXMAKINGDLL_SCI -iquote.objs30\include -I.objs30\include -I. -ID:\wx3\include -ID:\wx3\lib\gcc_dll\mswud -Isdk\wxscintilla\include -Iinclude\tinyxml -Iinclude -c plugins\autosave\autosave.cpp -o .objs30\plugins\autosave\autosave.o
[100.0%] g++.exe -shared -Wl,--dll -Lbase\tinyxml -LD:\wx3\lib\gcc_dll -Ldevel30 .objs30\plugins\autosave\autosave.o -o devel30\share\CodeBlocks\plugins\autosave.dll -Wl,--enable-auto-image-base -Wl,--add-stdcall-alias -Wl,--enable-auto-import -Wl,--no-undefined -mthreads -lcodeblocks -lwxmsw30ud
Output file is devel30\share\CodeBlocks\plugins\autosave.dll with size 798.93 KB
[ 50.0%] Running target post-build steps
[100.0%] cmd /c if not exist devel30\share\CodeBlocks mkdir devel30\share\CodeBlocks
zip -jq9 devel30\share\CodeBlocks\autosave.zip plugins\autosave\manifest.xml plugins\autosave\*.xrc
Process terminated with status 0 (0 minute(s), 6 second(s))
0 error(s), 0 warning(s) (0 minute(s), 6 second(s))
--- End code ---
Then, I try to use another method mention in gcc document, that is the "-include" command(this is the command to force include a header file firstly even there is no #include "xxx.h" statement in translation file), so I add on for this plugin in the compiler option:
--- Code: ----include "sdk_precomp.h"
--- End code ---
Now, I get the good result:
--- Code: ----------------- Clean: Autosave in Code::Blocks wx3.0.x (compiler: GNU GCC Compiler)---------------
Cleaned "Code::Blocks wx3.0.x - Autosave"
-------------- Build: Autosave in Code::Blocks wx3.0.x (compiler: GNU GCC Compiler)---------------
[ 50.0%] g++.exe -Wall -g -pipe -mthreads -fmessage-length=0 -fexceptions -Winvalid-pch -Wno-deprecated-declarations -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DcbDEBUG -DCB_PRECOMP -DWX_PRECOMP -DwxUSE_UNICODE -include "sdk_precomp.h" -DEXPORT_LIB -DEXPORT_EVENTS -DWXMAKINGDLL_SCI -iquote.objs30\include -I.objs30\include -I. -ID:\wx3\include -ID:\wx3\lib\gcc_dll\mswud -Isdk\wxscintilla\include -Iinclude\tinyxml -Iinclude -c plugins\autosave\autosave.cpp -o .objs30\plugins\autosave\autosave.o
In file included from <command-line>:0:0:
.objs30\include/sdk_precomp.h:1:2: error: #error "non pch file is used!!!"
#error "non pch file is used!!!"
^
Process terminated with status 1 (0 minute(s), 4 second(s))
1 error(s), 0 warning(s) (0 minute(s), 4 second(s))
--- End code ---
That means the compiler try to read the dummy header. (here, I still have only this dummy header file in the ".objs30/include")
Then, I place the "sdk_precomp.h.gch" back to the folder, and hit the "build" button gain, now, I see no #error report.
--- Code: ----------------- Build: Autosave in Code::Blocks wx3.0.x (compiler: GNU GCC Compiler)---------------
[ 50.0%] g++.exe -Wall -g -pipe -mthreads -fmessage-length=0 -fexceptions -Winvalid-pch -Wno-deprecated-declarations -DHAVE_W32API_H -D__WXMSW__ -DWXUSINGDLL -DcbDEBUG -DCB_PRECOMP -DWX_PRECOMP -DwxUSE_UNICODE -include "sdk_precomp.h" -DEXPORT_LIB -DEXPORT_EVENTS -DWXMAKINGDLL_SCI -iquote.objs30\include -I.objs30\include -I. -ID:\wx3\include -ID:\wx3\lib\gcc_dll\mswud -Isdk\wxscintilla\include -Iinclude\tinyxml -Iinclude -c plugins\autosave\autosave.cpp -o .objs30\plugins\autosave\autosave.o
[100.0%] g++.exe -shared -Wl,--dll -Lbase\tinyxml -LD:\wx3\lib\gcc_dll -Ldevel30 .objs30\plugins\autosave\autosave.o -o devel30\share\CodeBlocks\plugins\autosave.dll -Wl,--enable-auto-image-base -Wl,--add-stdcall-alias -Wl,--enable-auto-import -Wl,--no-undefined -mthreads -lcodeblocks -lwxmsw30ud
Output file is devel30\share\CodeBlocks\plugins\autosave.dll with size 798.93 KB
[ 50.0%] Running target post-build steps
[100.0%] cmd /c if not exist devel30\share\CodeBlocks mkdir devel30\share\CodeBlocks
zip -jq9 devel30\share\CodeBlocks\autosave.zip plugins\autosave\manifest.xml plugins\autosave\*.xrc
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 0 warning(s) (0 minute(s), 2 second(s))
--- End code ---
Thus, "sdk_precomp.h.gch" is now truly used by the sdk and other plugin targets. :)
ollydbg:
Well, I looked at the codeblocks-unix.cbp:
--- Code: --- <Unit filename="include/sdk.h">
<Option compile="1" />
<Option weight="1" />
<Option target="sdk" />
</Unit>
<Unit filename="include/sdk_common.h">
<Option target="sdk" />
</Unit>
<Unit filename="include/sdk_events.h">
<Option target="sdk" />
</Unit>
<Unit filename="include/sdk_precomp.h">
<Option compile="1" />
<Option weight="0" />
<Option target="sdk" />
</Unit>
--- End code ---
This means under Linux, we also have two pch files generated? (both are from the sdk target, not the same with windows, under windows, pch of sdk.h is generated in src target)
stahta01:
FYI: In Windows MinGW GCC a PCH only works inside of a real source file (headers files do NOT count).
In other words, a header can never include a real PCH file.
Edit: If on the command line you include a real PCH file like doing [-incude "sdk.h"] you will get a error normally if a header file in the project also includes that same PCH header of "sdk.h"; it a weird error message that I forgot what it says.
Edit2: You will have to put guards around the includes inside some source files around includes of the PCH; never tried the guards around the includes in header files since they needed to be removed I just removed them.
Tim S.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version