Re: help: how to compile c++



On Mon, 29 May 2006 21:51:43 -0600, Tom Harrington wrote:
In article <carl-09BD7F.20043629052006@xxxxxxxxxxxxxxxxxxxxxxxx>,
Carl Witthoft <carl@xxxxxxxxxxxx> wrote:

HI -- I'm well experienced in programming under unix, but haven't ever
played w/ c++. I have successfully compiled c programs on OSX (using
gcc of course). The problem is my child needs to write stuff in c++
for a professor. Her first try crashed, which is to say gcc didn't
like it.
So: can anyone tell me what I need to set up? Should gcc be able to
handle c++, or do I need to set some switches, or download different
libraries, etc?

Well, I normally don't say it, but since you're someone experienced in
programming on Unix, I think "RTFM" might be in order. "man gcc" is a
great place to start. This kind of thing is the same on Mac OS X as on
any other Unix box.

GCC normally uses the filename extension to decide what language is
likely to be in the file. File "foo.c" will normally be assumed to be C
rather than C++, but "foo.cpp" would be assumed to be C++.

There's also "g++", which is just gcc but with the default language set
to C++ rather than C. Replace "gcc" with "g++" and you may be set.

But note that if you compile and link in separate steps (as you would
likely do if using make), then the link step should be performed with g++
in order to get the right libraries. Just depending on the suffix is not
going to help you here. It's better to use g++ throughout when compiling
and linking C++ code.

Finally of course there's gcc's "-x" option, which allows you to specify
any supported language you like regardless of anything else. Name your
C++ file "foo.java" if you like, and the right "-x" flag will make it
work.



--
Dave Seaman
U.S. Court of Appeals to review three issues
concerning case of Mumia Abu-Jamal.
<http://www.mumia2000.org/>
.



Relevant Pages

  • Re: How do I install this missing library?
    ... you really should be carefully following LSTC's installation ... libg2c is part of gcc. ... to tell a newcomer to compile. ... like the source code to GNU tar, and make sure you understand what's ...
    (comp.os.linux.misc)
  • Re: Need your HELP: C in LINUX
    ... As for my editor preference, ... It has a built in function to compile the code using compiler specified in the configuration, but I don't even use that. ... Save your file from the editor, then type in the other window: "gcc file.c" - this is the simplest form of using gcc. ... It depends on what libraries you were using in Windows. ...
    (comp.lang.c)
  • Re: Nothing happens after freeing kernel memory
    ... different host libraries. ... but sometimes it won't compile through and leave me with some ... It builds binutils and a 'naked' gcc to start with. ... Some build systems also look at the CROSS or CROSS_COMPILE ...
    (comp.os.linux.embedded)
  • Re: Forth Licensing Terms
    ... when you compile code using GCC you specify what libraries your code ... GCC is itself GPL but as no part of GCC is compiled into ... You may statically link against a LGPL library ...
    (comp.lang.forth)
  • Re: HPGCC Questions ladies and gentlemen!!!
    ... No matter how you slice it in order to compile a C program you need to know ... it took a few hours just to get gcc running in my computer ... of the students that used an ide in the c++ class I took a few years ago. ... so why not use a data inspector if it's available? ...
    (comp.sys.hp48)