Mac OSX 10.5.4 wxWedgets2.8.9 + xcode3.0
下载:wxWedgets-2.8.9 源代码
在终端使用root登录
$mkdir /path
$chmod -R 755 /path
$cp <wxWidgets> /path
$chmod -R 755 /path/wxWidgets-2.8.9/
$mkdir /path/wxWidgets-2.8.9/mac-build
$cd /path/wxWidgets-2.8.9/mac-build
$../configure --enable-shared --enable-monolithic --enable-unicode --enable-universal_binary --with-mac --with-opengl --with-png=builtin --with-jpeg=builtin --with-tiff=builtin --with-expat=builtin
$nice make
$sudo make install
//set configure environment.plist
defaults write ~/.MacOSX/environment WXWIN -string "/path/wxWidgets/wxMac-2.8.9"; plutil -convert xml1 ~/.MacOSX/environment.plist
Compiling wxWidgets from Xcode
Note: Compiling from the terminal (explained below) is better supported, and more reliable.
Open up the wxMac-2.8.4 folder, then open up the src folder. In that folder you will find a file called wxWindows.xcodeproj ( NOT just wxWindows.xcode ). Double click on it to launch it. In the Xcode Build menu, make sure "Allow zerolink" is UNchecked. (right-click target, select "Get Info", select "Linking" in section "Collection")
In the Xcode wxWindows window click on the Active Target button and select "Build All" Click on the Build icon. It will take some time. When it is completed Xcode will have generated lots of warnings but they aren't fatal so forget it and get over it. You can then close the project.
There's a couple of interesting things, which should probably be fixed / or you should be aware of:
Now, time to try samples. Note that not all samples have Xcode projects.
In Mac OS X, the run time dynamic library loader wants to know exactly where all of the dylibs are. Most frameworks are installed in the system files, and to be safe Xcode normally builds against an OS SDK (eg 10.4u SDK) which is a known configuration of 10.4 systems that you're application can link to. (So you don't need to copy the libraries).
Mac OS X 10.4 ships with wxWidgets 2.5 pre-installed, for interest's sake.
Mac OS Applications are packages, which also makes it easy for you to copy the dylib into your app's package folder, and the linker will find it. With the Xcode project above (2.8.4), this layout will work:
myProgram.app/ myProgram.app/Contents myProgram.app/Contents/MacOS myProgram.app/Contents/MacOS/myProgram <-- this is your executable myProgram.app/Contents/Frameworks/wxmac.dylib <-- this is the dynamic library output of the wxWindows Xcode project. (other files suchs as Info.plist have been omitted from this list)
To achieve this in your program's Xcode project, add a build phase to "Copy Files" and copy to the Executable path, with a subpath of "../Frameworks". Then when you build your app, Xcode will copy the dylib into the app's package where the linker can find it. And your app is linking to a relative path, which is easily transportable!
Note that this will work automatically only if you built wxWidgets using the Xcode project. If you built using gnu autotools, and wish to bundle wxWidgets inside the app bundle :
Now try to build the demos from the Terminal window:
cd /path/wxWidgets/mac-build/demos cd life; make; cd .. cd bombs; make; cd .. cd forty; make; cd ..
Building Xcode Projects for wxWidgets Applications
If everything has worked so far, and you've picked a sample that matches the kind of program you'd like to write, then you are ready to try Xcode (you can pick any sample you like)
Note : These instructions were tested with Xcode 3 and wxWidgets 2.8.9.
- #include "wx/wx.h"
- class MyApp: public wxApp
- {
- bool OnInit();
-
- wxFrame *frame;
- public:
-
- };
- IMPLEMENT_APP(MyApp)
- bool MyApp::OnInit()
- {
- wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
- frame = new wxFrame((wxFrame *)NULL, -1, wxT("Hello wxWidgets"), wxPoint(50,50), wxSize(800,600));
-
-
- frame->Show();
- return true;
- }
Highlight your target under the "Targets" group in the tree on the left column
# if you did make install (make sure you get the right wx-config, you may need to adjust PATH) wx-config --cppflags wx-config --libs # if you left wxWidgets in-place cd /path/to/wxWidgets/mac-build
./wx-config --cppflags ./wx-config --libs
then copy the output of the two last commands. A conveniant way is to store them as envrionment variables to be called as $(VAR_NAME) from Xcode (see Setting Environment Variable For XCode for more info on this)
Warning : if you built wxWidgets as a universal binary, it will output flags like -arch ppc and -arch i386. Drop these flags because Xcode needs to manage Universal Binary stuff itself, passing flags to gcc without Xcode knowing will mix it up and result in linking errors.
If you chose a wxWidgets sample more complex than the dummy code posted above, it may also be necessary to copy the sample.xpm file from wxMac-2.8.x/samples to the folder above your project folder (you will know if Xcode gives the error "../sample.xpm: No such file or directory"). This should not be necessary for your own projects.
由于CodeBlocks8.02 在苹果上安装后,编译后的程序GUI界面不能响应,这个问题一直没解决,使用源代码安装太复杂,我尝试了几次也没能按装成功。不然使用CodeBlocks写wxwidgets跨平台的C++程序是一个不错的选择,功能强大。现在只能在Win平台写代码,然后copy到苹果平台,使用XCode编译链接成.App文件.这样也挺方便的。
The instructions above helped you to create a Carbon target.
Here are three other methods to use wxWidgets in a Xcode project