Re: Seeking help for C++ programming in linux

dmills_at_spamblock.demon.co.uk
Date: 10/18/03


Date: Sat, 18 Oct 2003 07:34:28 +0100

Xiaoshen Li <xli6@gmu.edu> wrote:
> Hi,

> 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
   here.....

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
   conditions.

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
   available there.

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";
        foo[4]='B';

    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.

HTH

Regards, Dan.

-- 
** 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.


Relevant Pages

  • Re: Good compilers.
    ... > What is a good compiler to use with windows and create GUIs? ... Typically and IDE provides at a minimum text editing ... commands to pass the source code to the compiler so the ... Using the Microsoft tool set is the natural choice to build Windows based ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Visual Studio 7.1 comments, dislikes, suggestions
    ... The F4 problem is the the worst, but also "Windows" dialog cause errors. ... keyboard thousands times per hour. ... It's interesting if Microsoft have plans to make IDE for experienced ... make an upgrade for MSVC 6.0 with the new compiler and old IDE. ...
    (microsoft.public.vsnet.ide)
  • Re: Processor question
    ... compiler, and it makes bare naked .EXE files. ... it could be that the IDE is being slowed by its poor ... interaction with windows in a way that the compiled program ...
    (sci.electronics.design)
  • Developing for Linux Shell Using Windows
    ... would allow me to develop on Windows but have the compiler and debugger and ... Code using Windows ... using a telnet session where the output is piped back to Windows IDE) ... Run (automatically Telnet in and run code leaving telnet session open) ...
    (comp.os.linux.development.system)
  • Re: hmm..interesting
    ... you've got a discussion of ARM vs Intel architecture here: ... And ARM is rapidly running away from RISC. ... mainstream (many netbooks and smartphones run Linux instead of Windows ... And hardly any C compiler does. ...
    (comp.sys.acorn.hardware)