pouët.net

Cross platform compiler and ides

category: general [glöplog]
 
Until now I code compiled code on Visual C 6. Now I'm searching for a good way to do cross platform code, mostly for Windows and Linux.

What I want to do is only multithreaded software rendering, so I just need a video buffer and a way to create threads (inline asm would be nice too).

What do you recommend me? Is there any ide working on Vista and Kubuntu? Is there any way to create code where the only need to port the code is just to say "compile it for windows" or "compile it for linux"?

Thanks in advance.
added on the 2008-08-28 12:29:59 by texel texel
it's more the way you write the code than the compiler or ide being used

that said, code::blocks is capable of reading vs2005 projects and runs on windows/linux

otherwise, there is also eclipse CDT that works on windows/linux/mac
In the end it's quite simple - keep all Windows related stuff in ONE source file and think of an easy and completely abstract interface that maps exactly what you want from it (that means: no #include <windows.h> etc ANYWHERE except in that one file). Then only use that interface. And when you're going Linux or Mac, just type a makefile, reimplement the functions in that one .cpp file (using high level libraries may help as the amount of rewrite will be far less) and there you go.

The header file of your interface should be as small as possible, so you not only get insanely low compile times but also can do compiler dependent stuff (in #ifdef blocks, things like inline definitions, intrinsics, pragmas etc) without making it too messy.

Inline asm is a bad idea though... if you really need assembly routines go for eg. NASM or YASM as those can output on any x86 based platform without change in syntax.

In the end, if you're taking care about writing C/C++ code that every compiler understands (good luck with that, VC is very forgiving, GCC is not and for some added fun the things it warns/fails you on will change with every revision :) you can have projects where only two files differ per platform; and as soon as these are set up it's indeed only pressing the right "compile for..." button :)
added on the 2008-08-28 12:42:03 by kb_ kb_
(and yes, we're doing this at our company for years now and I actually HAVE "make" buttons for various consoles in my VC toolbar ;)
added on the 2008-08-28 12:44:15 by kb_ kb_
the only nasty part is that you can't really use vc's project features so well when you have to "port" them to makefiles every time something changes. at least, i hate that part. a vc-project->makefile-for-linux converter would be cool.
added on the 2008-08-28 12:52:56 by skrebbel skrebbel
skrebbel: or, if you've got the time and energy (which I'd only recommend for big and/or commercial projects :) you can either use something like SCONS or write an own tool for creating the project files and makefiles from a simpler, abstract format. That's something we also do - defining projects in a smallish text file and then autogenerating VC projects and makefiles for all platforms from that.
added on the 2008-08-28 12:55:03 by kb_ kb_
SCons gets a big thumbs up from me. All IDEs on Linux are crap. After recently going back to VS recently I realise how bad Eclipse is.
For building, GNU make is all you need. All the other options (generating makefiles, using super fancy new tools) are either over-engineered, unavailable on some platforms, or depend on all kind of other stuff.

Building on windows, unix or osx with my makefiles is just the same:
Quote:
make all
(Admittedly even I can't fathom using plain old make so I require GNU Make 3.80 .. I just try making it my only dependency for building)

(essential reading about makefiles is the "recursive make considered harmful" paper)

As for IDE, I found that Xcode worked pretty well with makefiles. On Unix, the IDE is generally the whole OS. (ctags, awk, grep etc..)

For code, it's all about separating what's architecture dependent from what's really portable. It's about being conscious where you depend on your: compiler, os, libraries etc.

Also.. introduce dependencies only when absolutely necessary. Especially beware of dependencies with hidden dependencies underneath.

added on the 2008-08-28 13:36:08 by _-_-__ _-_-__
That's what I do in such cases:
* OS on development box: Debian
* Compiler: Native gcc for Linux builds & testing
* Compiler: mingw for crosscompiling Windows builds + Wine for testing (this works very well)
* autotools for the build process (ok, not everybody's cup of tea, but they work fine for me)
* Multithreaded+SW-Rendering: SDL is your Library. Win32 SDL works also fine on Wine
* Inline asm: Can't recommend it when you're using gcc. Use nasm. Keeping assembly code portable between x86 Linux and Win32 isn't a big deal.
added on the 2008-08-28 14:39:26 by Moerder Moerder
Quote:
Is there any way to create code where the only need to port the code is just to say "compile it for windows" or "compile it for linux"?


If you're using SDL, it boils down pretty much to building for the different platforms. All hail to SDL. You still have to worry about the "compile it for xyz" bit yourself, though.
added on the 2008-08-28 14:42:57 by Moerder Moerder
SDL FTW.
added on the 2008-08-28 14:44:59 by xeron xeron
Incidentally, I used GCC+MinGW on windows, and GCC on OS4 to code Planet Hively.

I'm guessing Linux has a GCC build available for it ;-)
added on the 2008-08-28 14:47:28 by xeron xeron
Thanks so much for the info. I will try in these days, I will post my results
added on the 2008-08-29 10:50:26 by texel texel
DO JAVA lol
added on the 2008-08-29 13:16:54 by Tigrou Tigrou

login