Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross platform programming [closed]

I need to write a small program for the university. The problem is, it has to be in C/C++ under linux, and I've never used linux, I anticipate having a lot of problems with the IDE, compilation, and all that.

Is it possible to code it under windows and then "copy/paste" the code and compile it under linux? What are limitations I should know about if it's at all possible?

It will be a small program, typical client/server communication using sockets.

like image 514
juan Avatar asked May 07 '09 19:05

juan


1 Answers

I think you should go ahead and do it under Linux (gcc?). This will teach you some stuff about 'old school' programming. Forget about using an IDE, use vim (if you already get it) or nedit (more like notepad).

Compile on the command line. Link it yourself. Write a make file to do this.

This is the basics. You need to understand it before using an IDE. Do this while you are still at university, because it's a pain and you will (and should) want to use an IDE for real work!

Also, a basic understanding of Unix is not hard to achieve (I have found my way around Solaris, Ubuntu and OS X, coming from a Windows background) - a few simple tutorials should get you up and running. For writing small school projects, there is not much you need to know: cd, ls, mkdir, make, gcc (be sure to use g++ for C++ projects - that has bitten me on my Mac before...). Stay close to your home directory (~).

Doing your project on the target system will help you get certain stuff right: When doing these simple sockets and pthreads examples, I found compiling and linking them to be non-platform portable. On certain systems, linking in the libraries needs to be done this way, on others that way.

BTW: If you really do want to do this under Windows, your best bet is to have a POSIX environment under Windows. POSIX sockets are different to the Windows networking model if I remember correctly.

Try either MinGW or Cygwin. Both should give you the *nix development environment under Windows. You can use your favorite text editor (a Windows port of vim?) and cmd.exe instead of bash for starting the compiler :)

EDIT: Sorry, if the tone is confrontational (according to comment). I will try to soften it a bit. It's just... I have seen quite a few people trying to learn C/C++ (or Java for that matter) with IDEs and have come to believe that they get in the way for starting off. Sure, you will need better tools for real life programs, but the overhead of project files etc. for school sample projects adds clutter. It also makes it harder to email your homework to your teacher - a zip with a bunch of .c and .h files and a makefile is really as simple as it gets...

like image 120
Daren Thomas Avatar answered Sep 20 '22 15:09

Daren Thomas