PDA

View Full Version : Is Programming C/C++ in Mac exactly the same as in Linux?




weizilla
Feb 9, 2008, 09:07 AM
Is programming in C/C++ in OS X exactly the same as programming in Linux or are differences between C/C++ in Unix and Linux? I'm a graduate student and I need to develop a lot of tcp/ip sockets/posix programs for a linux computer (server and client internet communication applications using 802.11 wireless) and I'm wondering if it's cross compatible. I also need to use a compiler which compiles C/C++ programs to an ARM architecture. I have a compiler which I'm using in Ubuntu right now but I don't want to get a mac then have to put Ubuntu on it just to do my thesis work.
I would also want to do some C# development with some application framework stuff like with Spring so I'm also wondering if that's possible on a mac and how compatible the final code would be on a windows machine.

It's too bad I can't test things like this at the mac store and it doesn't seem like any of the sales people would know. I was thinking I could always buy a macbook and try it out but I know that once I have the computer in my hand, i won't return it even if I have to put linux on it :o:)



Cromulent
Feb 9, 2008, 09:33 AM
Well as long as you stick to cross platform libraries then it will be cross platform compatible. You'll need to recompile it though I would imagine.

As for the compiler, you can compile your own GNU cross compiler if you have the time to burn. I can't tell you how to do it because frankly, I got stuck; but it is possible.

mail4asim
Feb 9, 2008, 10:51 AM
Have you checked at the Apple Store. Some of them do have a programmer working who can answer your questions.
btw, like the other person stated, it all depends on if you're using cross-platform shared libraries. Like if you going to be writing a gui program, don't use Cocoa .. use wxWidgets, GTK or some other library which works on all platforms.

jsw
Feb 9, 2008, 10:53 AM
One other thing to consider is obtaining VMWare or Parallels and simply running Ubuntu virtually.

yeroen
Feb 9, 2008, 11:12 AM
Mac OS X is part BSD, notably the networking stack. Porting applications, especially command line apps and server daemons, over from Linux/Unix over to Mac OS X is usually trivial.

In particular, Mac OS X comes with GCC as it's default compiler, just like Linux. There's the GNUARM toolchain for ARM compilation.

If you need a GUI front-end, you can use Qt which is available for Linux, Mac, and Windows. Qt also has a very nice networking API that's easier to program with than raw sockets.

You may have some luck with C# if you use Mono or dotGNU.

Soulstorm
Feb 10, 2008, 08:58 AM
Also, if you want to port your programs, you should know that XCode also uses the GCC as compiler. So, compiling in other platforms is a matter of setting your compilation options.

x704
Feb 10, 2008, 10:00 AM
C and C++ are in general, very cross-platform compatible, you can compile most any C or C++ program between linux, BSD, OSX, and Solaris with no problems... it may get annoying with the dependencys, but doable.

What is not cross compatible are the pre-compiled binaries without the source code. That is where windows losses it, they use things like directX, and other things where the source is not provided. OSX, Linux, and everyone else uses OpenGL for accelerated video.

Objective-C is different because it not used much outside of OSX... for Cocoa there is GNUstep, but its old, clunky, and annoying (so I hear). I do know a couple people that are working on a fork of GNUstep to fix up those problems and (eventually) provide a decent GUI lib, its called sidestep. I also know somebody working on GTK bindings for Objective-C (without needing Cocoa or *step).

So really you have to look into what you want to do and what libraries would best suit your needs.

weizilla
Feb 10, 2008, 07:17 PM
from the sounds of things, it seems like I shouldn't have any problems. All of my C/C++ programs are command line so I'm not worried about GUI or anything.

How compatible is mono and dotGNU with C#? or would it be better just to run a virtual version of windows and develop there?

Cromulent
Feb 11, 2008, 02:37 AM
How compatible is mono and dotGNU with C#? or would it be better just to run a virtual version of windows and develop there?

From what I have read they are okay, but are missing a few important things. If you are just doing C# for fun then I am sure they are fine. If you are doing it more seriously run Windows.