Re: Seeking help for C++ programming in linux
Date: Sat, 18 Oct 2003 07:34:28 +0100
Xiaoshen Li <firstname.lastname@example.org> wrote:
> I am going to do some C++ programming in Linux. I used to write C++
> programs in Windows using Visual C++ compiler. I have checked my
> computer (Red Hat 7.3 KDE), there is GNU C++ compiler available. I am
> wondering how much difference between this compiler and VC++.
> Alternative version of my question is, to program C++ in linux
> comfortably, do I have to learn linux programming?
> Thank you very much.
Well, there are a few things you need to understand:
1) g++ is just a compiler and NOT an integrated development enviroment,
you will need a text editor & debugger. Some linux text editors
include fairly sophisticated interaction with the debugger (gdb),
and there are a few IDEs which mostly work in a similar way.
Kdevelop springs to mind but there are plenty of other candidates.
In general unix developers are not very big on single IDE applications
as the shell is so powerful. However they are available and if VC is
what you are used to an IDE may be a easy intro.
2) g++ (for C++ use this not gcc as they link different libs by default),
does not support a lot of the types you will be used to from windows,
and obviously there is no MFC/COM stuff. There has been an implementation
of COM like functionality but it is not the way things are commonly done
3) The unix way is NOT the windows way, while standard compliant C++
should (modulo compliance issues) work on both platforms, the gui,
threading, library handling, default configuration file handling,
IO (beyond iostream) & syncronisation mechanisms are all different
to a greater or lesser degree. In particular I would note that
configuration data is never stored in the same directory as the
application binary (how would this work with a dozen users?), and
that WaitForMultipleObjects or whatever it's called does not exist
and is in fact difficult to implement without creating race
4) You will need to aquire at least a rudimentary understanding of
makefiles (not hard, but watch the fact that a tab is not the same
thing as any number of spaces....
5) CVS is worth the trouble, and unlike sourcesafe (which in my experience
is nothing of the sort), it actually works reasonably well.
6) man (and apropos) is your friend, LOTS of excellent documentation
7) Use the warning options to the compiler, I like as a basic set,
g++ -W -Wall -O2 -g hello.cpp -ohello
8) do not call your program test, there is often a shell builtin command
called test, this can cause much confusion.
9) The math library is not linked by default, if you use any math library
functions you will want to add -lm to the end of whatever invocation
of g++ does your final link.
10) (Minor but trap for the unwary), string literals are read only,
unlike IIRC in windows, so
char *foo="Bar bar Black Sheep";
Will cause a 'segmentation fault' (windows GPF), on execution.
char=.... would have been OK however.
If you are writing deliberately portable code you will not find things
too different, once you get past the command line options to the compiler,
if you write complex gui code with the application logic mixed in with lots
of calls to MFC then you will have 'fun' with the port....
I do not know what version of g++ RH7.3 shipped with, it might be
worthwhile finding a more up to date distro as the language was only
fairly recently standardised and upgrading c++ compilers and libs (and
having everything still work) IS rocket science.
-- ** The email address *IS* valid, do NOT remove the spamblock And on the evening of the first day the lord said........... .... LX 1, GO!; and there was light.