This post is related to getting started with CodeBlocks on Mac OS X.
It is assumed that you've already disabled two plugins that cause CodeBlocks to crash:
keyboard shortcuts and code completion (Menu->Plugins->Manage plugins).
Tutorial:
http://wiki.codeblocks.org/index.php/WxSmith_tutorial:_Hello_worldCodeBlocks: v.13.12
OS: OSX 10.11.6 (El Capitan)
Compiler: g++ (clang compiler installed with Xcode command line tools)
wxWidgets: v.3.1.0
The following may also be applicable to wxmac (wxwidgets 3.0.2).
Follow instructions in wxSmith tutorial through the Build and Run step.
1. Problem: The Build appears to work but when Run, the Window never appears.
An Information popup window appears each time Build and Run is clicked:
"It seems that this project has not been built yet.
Do you want to build it now?"
Fix:
First, click on "Build log" under "Logs & Others" at the bottom of Code:Blocks.
If you see:
error: no suitable precompiled header file found in directory 'wx_pch.h.gch'
Then change the precompile strategy:
Menu->Project->Properties...
Look down for Precompiled headers, under Strategy, choose third option:
+ Generate PCH alongside original header (default)
Click OK
Menu->Project->Build options...
In left panel, select: Plain (both Debug and Release targets)
Tab: Compiler Settings
SubTab: Other Options
In the textbox, add an include path to the current project folder (-I.):
(Note: the -I. must be above the -include line)
`wx-config --cflags`
-Winvalid-pch
-I.
-include wx_pch.h
Click OK
Now, use Finder to delete wx_pch.h.gch from your project folder.
Click on the Projects tab under Management to make sure you've selected your project (Bold).
Then, build and run again.
-----------------------------------------------------
2. Problem: Can't find wx/wxprec.h
In Build messages, you may see:
fatal error: 'wx/wxprec.h' file not found!
If so, fix:
Menu->Project->Build options...
Tab: Compiler Settings
SubTab: Compiler options
Change the wx-config call to include the full path to wx-config.
(Note: In Terminal, you can determine the path to wx-config using 'which wx-config' without the quotes.)
`/usr/local/bin/wx-config --cflags`
-Winvalid-pch
-I.
-include wx_pch.h
And:
Tab: Linker Setting
In "Other linker options", include the full path to wx-config:
`/usr/local/bin/wx-config --libs`
Click OK
(Note: Alternatively, you can define WX_CONFIG in Menu->Environment->Environment variables.)
Then, build and run again.
-----------------------------------------------------
3. Problem: Can't find Resource Compiler
In Build messages, you may see:
/Developer/Tools/Rez No such file or directory!
Fix:
Apple has apparently moved Rez to /usr/bin:
Menu->Settings->Compiler
Tab: Toolchain executables
Resource compiler: /usr/bin/Rez
And:
Menu->Project->Build options...
In left panel: Debug
Tab: Pre/posts build steps
Change the path here, too:
/usr/bin/Rez -d __DARWIN__ -t APPL Carbon.r -o $(TARGET_OUTPUT_FILE)
And:
In left panel: Release
/usr/bin/Rez -d __DARWIN__ -t APPL Carbon.r -o $(TARGET_OUTPUT_FILE)
(Note: Alternatively, since both Debug and Release are the same, you
can copy this line to Plain (both) and delete it from Debug and Release.)
Click OK
Then Build and Run again.
-----------------------------------------------------
4. Problem: Now the window appears but it can't be closed.
Clicking Close on the window (Red X at top-left of window) doesn't close the window.
Menu->File->Quit doesn't close the window.
(However, you can use CodeBlocks Menu->Build->Abort to kill the window.)
Fix:
In the OnQuit() method, call Destroy()
void PlainFrame::OnQuit(wxCloseEvent& event) {
Destroy();
}
(The last step is not a CodeBlocks issue but is needed for success.)
Rebuild and Test.
An example MenuBar and Output Window when tutorial is completed is attached.
Hope this helps someone, please report your success or failure.