Code::Blocks

User forums => General (but related to Code::Blocks) => Topic started by: ridge on January 21, 2017, 03:54:33 am

Title: [Solved] wxSmith first tutorial doesn't work using CodeBlocks on Mac OS X
Post by: ridge on January 21, 2017, 03:54:33 am
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_world

CodeBlocks: 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.
Title: Re: [Solved] wxSmith first tutorial doesn't work using CodeBlocks on Mac OS X
Post by: BobsTheDude on March 04, 2019, 12:58:13 pm
I have tried many different tutorials to get Code::Blocks and wxwidget to properly function together on a MacOSX. After many days I found this post and seemed to offer a resolution. But alas, following this tutorial I still cannot get Code::Blocks and WxWidgets to play together.

I am using the following:
macOS Mojave, Version 10.14.3
Code::Blocks Release 17.12 rev 11260 (2017-12-30 18:39:11) gcc 4.2.1 Mac OS X/unicode - 64 bit
wxWidgets 3.1.3

Do you have an updated tutorial or does anyone have directions on how to resolve this issue.

Thanks for your time.
 
Title: Re: [Solved] wxSmith first tutorial doesn't work using CodeBlocks on Mac OS X
Post by: oBFusCATed on March 04, 2019, 03:00:32 pm
Can you post some details about the issue you're having?
Title: Re: [Solved] wxSmith first tutorial doesn't work using CodeBlocks on Mac OS X
Post by: BobsTheDude on March 04, 2019, 04:41:41 pm
Well, for some reason in the middle of getting wxWidgets to work with CB I switched from CB 13.12 to 17.12. for some reason, anything type into project build options is mangled. Such as wx-config --cflags is changed to wx-config —cflags and the command line if copied and pasted to terminal does not work but it is the exact command(looks like its auto correcting). So this may be my issue, so I am switching back to 13.12 where the command is not modified in any way and starting from scratch. If I can ever get wxWidgets to correctly work with CB 13.12, I will go back to 17.12 and try and see whats going on.
Title: Re: [Solved] wxSmith first tutorial doesn't work using CodeBlocks on Mac OS X
Post by: BobsTheDude on March 04, 2019, 05:09:06 pm
I dropped back to 13.12 and fixes supplied in the original post by ridge worked. I can verify this does not work for 17.12, thanks ridge, I have a bit of hair left.
Title: Re: [Solved] wxSmith first tutorial doesn't work using CodeBlocks on Mac OS X
Post by: oBFusCATed on March 04, 2019, 06:26:33 pm
Have you tried to right click in the text control and disable the smart-dashes option?
Title: Re: [Solved] wxSmith first tutorial doesn't work using CodeBlocks on Mac OS X
Post by: BobsTheDude on March 04, 2019, 07:29:46 pm
I have not tried anything yet, I am under the gun to get this application out the door. I'm a XCode guy, I have never used CB before but I needed a way to get some kind of WYSIWYG for wxWidgets. I would prefer to use the 64bit version, but once I get this project completed I will put more effort into why this is not working for 17.xx.

Thanks,

B