When you run the app you will get some output like this in the .
Porting a Mac program to Windows using The Cocotron. Introduction. If you want some background on what The Cocotron is and alternative ways of porting applications from the Mac to Windows, please read the first and second part in this series. Setting up The Cocotron for remote debugging.
Installing The Cocotron is a three step process: Download the Install. CDT zip file, decompress it and run the Install.
After updating Xcode, launch and run the Xcode. Mac OS X El Capitan will alert you when you enter a command in the terminal that requires Xcode Command.
You should be at least familiar with the basics of the Terminal. Run the installer and install everything other. Setup up and Xcode C++ Terminal application. Use Xcode to Program C++ - Duration.
I write a simple.c file for the program and using the g++ compiler in terminal I compile the file, but how do I run the. Hi All Have been using the Terminal to compile programs built through Xcode but now want to use Xcode itself. Everytime I press build and go it builds. How to build and create.app file from out side Xcode i.e. Terminal (Go to Spotlight and. How To Run Terminal.app from Xcode Nov 03 2011, 22:41.
CDT script it contains. I think CDT stands for Cocotron Developer Tools. This installs a copy of gcc and related tools that you will required for cross- compilation.
It will also install required Min. GW libraries and W3. API libraries for linking Windows projects. Check out a copy of The Cocotron code.
The repository has recently moved to Mercurial, so you'll need to have a copy of Mercurial or check out the Subversion mirror. Open the Cocoa. xcodeproj and build the project. Download a copy of xcxdb- Installation. XCXDB probably stands for Xcode Cocotron (X)cross De. Bugger. The third point is not strictly required for using The Cocotron but is required for remote debugging as it installs a version of gdb that will allow remote debugging between Xcode and Windows. The XCXDB install has the added advantage that it adds a Template to the Project Templates that will create a Windows debuggable project without needing to mess around with specific project settings.
You can add The Cocotron and XCXDB settings to an existing project but it takes a bit more effort: apply the Build settings for CDT and then, from an XCXDB project created from the template, copy the manifest, icon, Remote- Target. GDB connection to . You could also use VMWare, Parallels or a separate, dedicated Windows machine. Virtual. Box is cheaper than these options (it's free) but is also the slowest so you'll want a faster machine. Running a virtual machine and Xcode on the same computer also uses lots of RAM. You could probably manage in 4.
GB of RAM but I have 6. GB of RAM and have contemplated getting more to accomodate Virtual. Box, Xcode and my other regular applications. To make a virtual machine work, the best approach is to make the virtual machine use a . This gives it its own IP address on the local network.
Incidentally, I had to switch from Virtual. Box's default AMD network driver to the Intel driver — since the AMD driver would crash periodically while debugging, causing the whole virtual machine to lose network connectivity until I restarted it.
Once the Windows virtual machine has its own IP address, edit the IP address in the . Make sure the Firewall on the Windows machine allows access to 9. XCXDB uses for debugging). You can use another port if needed, just use a different port in Remote- Target. You also need to ensure that the build location for your Xcode project is a shared volume that both the Mac and Windows machines can access. I chose to use Virtual.
Box's . I chose to use an MSYS terminal client to navigate to the /z/Projects/XCXDB- Sample/build/Debug- cocotron- win. XCXDB- Sample. app directory (download MSYS and its dependencies from mingw. The reason why I used MSYS instead of a DOS command prompt like cmd.
MSYS allows the standard out and standard error of any running application (this includes NSLog() messages from Cocoa) to work for applications (otherwise these facilities are only visible to dedicated command- line programs in Windows). MSYS also offers a more familiar (if slightly quirky) bash shell environment. Once you're in the XCXDB- Sample. Normally in XCXDB, this command is run from the debug. You can create a shell script if you prefer.
The Windows command shell will now display: . If all has gone well, the status bar at the bottom of the project menu will build and then display . You need to tell GDB to try to connect.
With the one of the Xcode project windows selected, type Command- Option- P (Debugger continue). If the communication between Mac and Windows isn't working you may see an error in the Debugger Console. You may even encounter bugs.
To help you fix these issues, you'll probably want to build The Cocotron's Cocoa. Debug and keep the App. Kit. xcodeproj and Foundation.
This will build debug information into the App. Kit and Foundation DLLs and will let you debug problems in these frameworks. Since the debugger is configured to communicate via PIPE instead of the interactive terminal, you can't enter GDB commands into the Command Console in Xcode.
You can add extra commands to the Remote- Target. Every time I started listening on a socket, GDB reported a SIGSEGV signal. The program didn't crash (I'm not sure it was a real SIGSEGV) but it paused the debugger.
If this happens for you and it gets too annoying, you can add the line . Often, I could only set breakpoints before the program started or when the program was already stopped at another breakpoint. If anyone finds away around this nuisance, I'd like to know.
Code which won't . Don't misunderstand me: it is very difficult; but since it has little to do with The Cocotron, I won't discuss that work here. Almost everything involving sockets.
Serve. To. Me includes an HTTP server and does a lot with BSD socket communication. None of this worked initially. The Cocotron itself doesn't implement sockets — instead that falls directly through to Win. Sock's implementation. Most socket code just required the Windows headers to be included: #if . Examples include inet. You will need to reimplement these yourself.
If you Google for them, you'll find implementations around. Quirks and omissions in the Min. GW libraries. The Min. GW libraries implement a lot of POSIX functions but certainly not all. One of the more annoying omissions for me was mkdtemp() (which creates temporary directories in a safe manner). In the end I had to find an open source implementation of this function in Free.
BSD and included that in my project. A few other functions like random() were missing (using rand() instead was sufficient) and some functions like mkdir() took a different number of arguments (again a simple #define to change the arguments was sufficient). Objective- C Runtime Differences.
The Cocotron's Objective- C runtime does not support +load methods at this time. This meant that I had to move all the code that I previously invoked in +load methods into another location. Not really a big difficulty — I registered service handlers for my HTTP server in a different location. Unimplemented behaviors. The Core. Foundation functions for generating UUIDs — CFUUIDCreate and CFUUIDCreate. String — were not implemented.
With functions like this, you need to choose: do you add the functionality to Cocotron and submit the changes back to the trunk, or do you just use the Win. With other functions I used that weren't implemented, like Sec. Keychain. Find. Generic. Password, I implemented the changes properly in The Cocotron and committed back to the trunk (I feel bad, looking at my additions, that don't match the indentation of the other code). With UUIDs though, I couldn't be bothered working out if a platform independent or multi- platform solution was easy or possible, so I just slapped the Win. Responding to clicks in the icon and showing a menu, then minimizing the window into that icon to show that the program is still running took a lot more.
It's very strange to include all this Win. Cocoa application. Windows does not support that. My code previously used - . The Cocotron does not implement this method. At first I thought it was just a missing implementation that I could add.
Then I learned that Windows can't wait for a notification on an unnamed pipe. The select function or the Wait. For. Multiple. Objects in Win. This actually required refactoring my code to use read. In. Background. And. Notify instead. This isn't a huge change but it is a situation where Windows was actually incapable of replicating the exact behavior and changing the program to work in a slightly different way turned out to be the easiest approach.
Obviously, it is possible to implement an abstraction around the whole concept of pipe and file handles to replicate the same functionality but that's a lot of work, and is antithetical to how the rest of The Cocotron works (it aims to be a thin implementation of Cocoa on top of Win. Windows filesystem.
Obviously, hardcoded paths need to change when you move to Windows. Unfortunately, there are a couple other quirks to handle. Serve. To. Me uses lstat and readdir to traverse directories instead of any higher level function (for performance reasons discussed in an earlier post). Min. GW provides a stat implmentation for file information but does not provide lstat, so handling Windows Shortcuts would be tricky — I didn't try.
Unfortunately, stat doesn't handle UNC paths. These are Windows network paths for volumes that aren't mounted as drive letters. For this reason, I decided to move to a higher level API. The correct way to do this under Win.
Get. File. Attributes. Ex. W. However, it turns out that it was easier to simply revert to the higher level NSFile. Manager API for getting file system information. This API is fully implemented by The Cocotron, supports UNC paths and worked fairly efficiently in testing.
Aside: the function name Get. File. Attributes. Ex. W is amusing evidence of the age of Win.
The original function, Get. File. Attributes is still there but is just about useless — it was deprecated in 1. Win. 32 never fully committed to Unicode so the function has to point out: Warning! But only in some cases.
Time taken. Porting Serve. To. Me to Windows took me just over 2 weeks. This time breaks down as: Setting up my Windows virtual machine and The Cocotron and getting remote debugging working: 2 days. Commenting out code which doesn't work up- front and getting the program to launch: 2 hours. Re- adding functionality that was missing or didn't immediately work: 1. Fixing quirks associated with sockets and port mappings: 1. Building or reimplementing 3rd party libraries for Windows: 4 days.