# compiling c++



## nr7 (Dec 15, 2002)

is there a way for me to write and compile c++ code in Darwin?


----------



## jesustoast (Dec 15, 2002)

You can use g++ to compile c++ code.

'man g++' to read the manual.


----------



## nr7 (Dec 17, 2002)

I only got a error when typing "man g++". Something I should install maybe?


----------



## Captain Code (Dec 17, 2002)

You need to install the developer tools, which you can get at developer.apple.com
It comes with g++, and a whole lot of other good stuff


----------



## nr7 (Dec 17, 2002)

Ive already got the developer tools. Anything special I have to to? Havent tried it yet...just asking.


----------



## wiz (Dec 22, 2002)

make sure ur man path is set to point to the correct location,

echo $manpath or just type manpath to check where it points to


----------



## JavaNick (Dec 25, 2002)

Apple's UNIX implementation (Darwin) is really an update/upgrade of the OpenStep OS from NeXT. For example the usual "gcc" compiler in UNIX is "cc" in Darwin. When you type "man cc" you get a quick 2 or 3 line reference that points you to the developer documentation path & docs. They're html files. Try these docs, and I also believe (not certain) that the "cc" compiler will also compile     "C++" code besides "C" and  "Objective C" code. 
Good luck,
JavaNick


----------



## nr7 (Dec 26, 2002)

ok guys, dont give me up now! But I have some trouble with the "man".

i type "manpath" ---->  /usr/share/man
Is this ok?
typing "man cc" only gives me "No manual entry for cc". Is this because  my man path isnt set to point to the correct location. What would be the correct location? 

As you may notice my UNIX skills arent too big....but Im learning, Im learning!


----------



## hazmat (Dec 27, 2002)

Yeah, my gcc man pages are under /usr/share/man.  This is OS X 10.2.3.  FWIW, both cc and gcc are symlinks to gcc3.  Same goes for the man pages for cc, gcc, g++, etc.  All symlinks to gcc3.  Exactly what error do you get?


----------



## anarchie (Dec 28, 2002)

Okay....um...you said you have the Developer Tools.  Have you installed them?


----------



## hazmat (Dec 28, 2002)

Of course.  You won't have the compiler without the dev tools.


----------



## JavaNick (Jan 2, 2003)

The "man" path problem I'm not sure about, but as far as the cc compiler documentation, there is a pdf that comes with the dev tools, you'll find it in Developer/Documentation/Developer Tools/Compiler/Compiler.pdf - There are also html files there which I think (haven't really looked) refer to the same pdf file in chapter form. BTW - I wrote a simple "C" program to check out the compiler, my file compiles OK but I'm having an issue with creating an executable. I'm running 10.1.5; I'll have to do some more research. Good Luck!


----------



## rhg (Jan 2, 2003)

Darwin has an info page for cc installed. Try "info cc" instead of "man cc".

Hints: use cc for plain C programs and c++ for C++ programs. Both refer to the same GCC 3.1 but the compiler operates in different modes depending on its basename.

Have you already compiled something successfully?


----------



## nr7 (Jan 3, 2003)

"info cc" is working!
Ive just downloaded the latest version of dev tools. Havent had the time to install it yet. Doing it today. No I havent compiled something successfully yet (in Darwin).


----------



## nr7 (Jan 3, 2003)

"info cc" is working!
Ive just downloaded the latest version of dev tools. Havent had the time to install it yet. Doing it today. No I havent compiled something successfully yet (in Darwin).


----------



## rhg (Jan 3, 2003)

This is a simple example program:

#include &lt;iostream&gt;
int main()
{
   std::cout &lt;&lt; "Hello World" &lt;&lt; endl;
   return 0;
}

Save this into a file named hello.c and compile it with:
c++ -o hello hello.c

You will get an executable named "hello" which you can simply execute with:
./hello
(read: dot-slash-"hello")


----------



## rhg (Jan 5, 2003)

Regarding MANPATH: You need to set the MANPATH environment variable. The easiest way to do so is to edit /etc/profile and add the following two lines:

MANPATH=/usr/share/man:$MANPATH
export MANPATH

(no spaces in the MANPATH= definition!)


----------



## nr7 (Jan 7, 2003)

Ive just successfully compiled  "hello world".  Just had to add a ".h" after "iostream". Nice. Thanks everyone! You have been very helpfull. Its about -25 degrees celsius in Norway theese days, so its nice to be inside doing some compiling


----------

