What is the comand to compile a c++ code in Unix. I have only used Borland C++ on win but have heard that UNIX has a integrated compiler.
Yes there is a compiler in Unix, its called g++
g++ [option | filename ]
g++ is a script to call gcc with options to recognize C++. gcc processes input files through one or more of four stages: prepro-cessing, compilation, assembly, and linking.
C++ source files use one of the suffixes `.C', `.cc',`.cxx', `.cpp', or `.c++'; preprocessed C++ files use the suffix `.ii'
In g++ options must be separate: "-dr " is quite different from `-d -r ' and so on..
For more information check your g++ man pages
Thanks for your help! I hope that i some day can say that I know UNIX...
I tried to run g++ ut got an error about <iostream.h>
As I understod it is supposed to be located in /usr/include but it is not there. Have i got it wrong?
The error msg I got is:
hello.cpp: In function `int main ()':
hello.cpp:5: no match for `_IO_ostream_withassign & = const char[13]'
/usr/include/g++-3/iostream.h:243: candidates are:
_IO_ostream_withassign &_IO_ostream_withassign::operator= (ostream &)
/usr/include/g++-3/iostream.h:245:
_IO_ostream_withassign &_IO_ostream_withassign::operator=
(_IO_ostream_withassign &)
and the source code is:
#include <iostream.h>
main ()
{
cout >>"Hello World\n";
return 0;
}
Ok, now I do got error:
hello.cpp: In function `int main ()':
hello.cpp:5: `cout' undeclared (first use this function)
hello.cpp:5: (Each undeclared identifier is reported only once for each
function it appears in.)
`cout' undeclared? I don't get this....
Finally I got it working!
Feels quite embarrasing to put the error from one of the most simple program ever on the web. ut for all newbies - Watch ad learn.
The rigth code is:
#include <iostream.h>
int main()
{
cout << "Hello World!\n";
return 0;
}
Take care!