Creating Xcode projects for wxWidgets applications

From WxWiki
Jump to: navigation, search
This article applies to the following versions
Platform wxWidgets Xcode
Mac OS X 10.8.2 3.0.0 Cocoa 4.6.3
Status: Up to date
Note: This article applies to Xcode 4 with wxOSX/Cocoa 3.0.0 but should work also for 2.9.5 (before that, some files are missing (like the wx_cocoa.xcodeproj (file that builds the libraries). For older versions of OSX/Xcode, see Creating Xcode 3 projects for wxWidgets applications

Create the library

This part is pretty simple.

  • Open the file "wxcocoa.xcodeproj" located in the "wxWidgets-3.0.0/build/osx" folder
  • Select the right Scheme (Product > Scheme > dynamic or static) then select "Edit Scheme":

In "Build Configuration", select "Release" or "Debug" as you wish. Your project will have to be also matching that parameter.

  • then Run! And go get you a cup of coffee while it's building.

When it's finished, the resulting .a file should be located in this folder : /Users/me/Library/Developer/XCode/DerivedData

Compile the basic

  • Open "minimal_cocoa.xcodeproj" (in the \Samples folder), because we will need this project for the new one we create.
  • Go to "XCode > Preferences > Downloads" and install the "command line tools"
  • Next : select "new project > cocoa application"

Xcode4 newproj.jpg

  • Remove *every* file of the newly created project
  • Drag'n drop these files from the project "minimal_cocoa.xcodeproj" :
  1. wxcocoa.xcconfig
  2. wxdebug.xcconfig
  3. wxrelease.xcconfig
  4. Info_cocoa.plist
  5. minimal.cpp

select "copy items" on the window that opens

  • rename the main target Static or Dynamic according to the lib you built
  • select the project (above the Targets) and in the next pane, there is an "Info" Pane.

In the "Configurations" area select the files for Debug and Release:

Final -> wxdebug or wxrelease

Static -> wxcocoa for both


  • Select the main target. In the next pane on the right select "Build Phases" then reveal the pane "Link Binary with Libraries".

Then drag'n drop the Static or Dynamic library (.a) created earlier.

  • In the same window there is a tab "Summary", a field "OS X Application Target" and a button "Choose Info.plist File..."

click on this and select the previously copied file "Info_cocoa.plist"


In Build Settings

  • with Target still selected, click on Build Settings. Click then on the icon in the lower right part (the "add build setting" icon) then select "Add user-defined setting"

Call it "WXROOT" and in the right part put the path to the wx main folder. Should be something like :

"WXROOT" "/Users/me/Downloads/wxWidgets-3.0.0"

Also add user defined setting "WXPLATFORM" which can be copied from the minimal project, it should be something like:


  • Find a line called "Header Search Paths".

In that field enter : "$(WXROOT)/build/osx/setup/cocoa/include" and on another line "$(WXROOT)/include". On the next line, enter the path to the minimal project ; something like : "/Users/me/Downloads/wxwidgets-3.0.0/samples/minimal" (so it finds the file sample.xpm)

  • Change "Prefix header" to "$(WXROOT)/include/wx/wxprec.h"
  • Also change:
  1. "C Langage Dialect" to "GNU99"
  2. "C++ Langage Dialect" to "Compiler Default"
  3. "C++ Standard Library" to "GNU C++ standard library"
  • Select the line "Base SDK" and choose "Current OS X"
  • In "other linker flags" line enter "$(OTHER_LDFLAGS) -lz"
  • Copy the "Preprocessor macros" lines (still in Build Settings) from the project "minimal_cocoa.xcodeproj" to your main project.


  • select "Alway search user paths" to "yes" for both Projects and Targets


Edit scheme : (Menu Product > Scheme) to match the Debug or Release library you built