wxWidgets samples XCode compilation tutorial

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 30, 2020 2:22 pm
Location: France / Netherlands

wxWidgets samples XCode compilation tutorial

Post by BenKissBox » Sat Feb 01, 2020 4:23 pm

Hello everybody,

I found that only one "samples" project has a XCode project files, all other sample projects only have VS and Linux related project files. Creating XCode projects for the samples is not a complex tasks but I wanted to share my work, if it can help any other users.

Instructions given here have been tested on XCode 7, XCode 9 and XCode 10 for wxWidgets 3.1.3

First of all, you will need to compile the wxWidgets library
- unzip the whole wxWidgets package on your hard disk
- launch XCode
- open the /build/osx/wxcocoa.xcodeproj file
- open Project navigator (leftmost icon) and click on wxcocoa project (blue icon) in the info pane

You should see now the Deployment Target list and Configurations. Select the minimum OS X version you will need to run the application using your library (for XCode7, it is set to 10.11 by default, which may be problematic if you want your application to run on older Mac)

Go to Product menu and click Build. Now you have time to take a few coffees :mrgreen:
This command will build a Debug version of the static library (libwx_osx_cocoa_static.a). You will find this library in /build/osx/build/Debug

If you want to generate a Release version of the library, go in Product menu and choose Build For / Profiling.
(And you will now need much more coffee, as the build time is doubled... because the library is compiled both for 32-bit and 64-bit...)
The library is located in /build/osx/build/Release

Now, the fun part begins... :D

Close XCode (or at least, close the project). Take care of one thing : wxcocoa.xcodeproj project can not be opened in two projects at the same time [-X (and opening the minimal project will make a conflict since it will try to open the library project again)

I will show you here how to build the "widgets" sample, but the same procedure applies to any other sample project

Go to /samples/minimal and copy the two following files
* info-cocoa.plist
* minimal_cocoa.xcodeproj

Go to /samples/widgets and paste the two files from minimal
Rename minimal_cocoa.xcodeproj into widgets.xcodeproj

The following step is MANDATORY, even if I can't explain why XCode behaves like this... I have found that linking the static library from the /build folder does not work... sooo... copy the libwx_osx_cocoa_static.a file from /build to /sample/widgets (that's the only way I found to solve the issue for now)

Open XCode and load widgets.xcodeproj project
Delete the wxcocoa.xcodeproj project you see in widgets top project (WARNING : only REMOVE REFERENCE, do not send the project to trash !!!)
Delete minimal.cpp file (should be displayed in red for now)
Add all cpp files in the src folder. Add also the native_wrapper.mm file !. You should have 33 files included.
Once all files have been added, select all of them and check both "static" and "dynamic" in Target Membership (right side of XCode project window). Make sure that you have a check mark, not a minus sign ! (would mean some files are not included in the compilation list)

Select widgets project (top of navigator) and click on "Dynamic" target. Set bundle identifier to org.wxwidgets.samples.widgets.
Do the same thing for the "Static" target.
As you are on "Static" target, click on "Build phases", click then on "+" in the Link Binary with Libraries section. Select the libwx_asx_cocoa_static.a file you have copied in the widgets folder before.

We are almost done... :P
Using list on the top, select "Static" scheme, then "My Mac 32 bits" or "My Mac 64 bits" depending what target you want to build

And now.... cross your fingers and do the long awaited Command-B 8) (or Product / Build)

After a few seconds, you should see the nice "Succeeded" message. Click Run... and here is what you will see (see attachment)

For reference, I have started to create the missing XCode project files for the samples. They are available here https://github.com/imodularsynth/wxWidg ... de_Samples

Capture d’écran 2020-02-01 à 17.12.57.png

Part Of The Furniture
Part Of The Furniture
Posts: 4828
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxWidgets samples XCode compilation tutorial

Post by ONEEYEMAN » Mon Feb 03, 2020 3:30 pm

For the OP and whoever will read it in the future:

Xcode project for wxWidgets itself sometimes are not updated - especially if the new source code/header fikle is added to the library.

And so the best way to compile the library itself is still thru the Terminal with the plain old "configure && make".

Thank you.

Post Reply