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:
#error "non pch file is used!!!"
So, if the original "sdk_precomp.h" is used, the compiler will show an error.
2, this is my modified "include\sdk.h"
/*
* 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
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:
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.
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.
-------------- 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))
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:
Now, I get the good result:
-------------- 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))
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.
-------------- 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))
Thus, "sdk_precomp.h.gch" is now truly used by the sdk and other plugin targets.