How to compile hello.c using g++?

April 5, 2011 at 07:07:21
Specs: SunOS 5.9
I am playing around with re-learning C/C++ on a SunOS server. I'm not an admin on the box.

My program, hello.c is very simple.
// test program
#include "iostream.h"

int main()
cout << "hello world\n";

When I compile and link with g++ hello.c -o hello, I get this warning about my file containing a deprecated header. Assuming that is not a problem.

when I run my program


I get the following error message: hello: fatal: open failed: No such file or directory

Is this some issue with my path environment? I did not install the g++ compiler, I'm not the admin of the box, just feeling my way around.


See More: How to compile hello.c using g++?

Report •

April 5, 2011 at 08:13:28
Compile the program with the command (assuming that you are in the source directory):

gcc hello.c -o hello

Run it with the command:


If either of those fail then there is some problem with your gcc installation, but try them and see. You actually might find it easier to download and install Oracle Solaris Studio from here: .

Report •

April 5, 2011 at 08:28:56
thanks for the reply. I found out that in our environment, while the gnu compiler is installed, it may not be installed correctly. The correct compiler in our environment is the solaris "cc" command.

thanks again.

Report •

May 5, 2011 at 06:35:52
When you have c programs you must use gcc and when you have cpp programs (c++) you must use g++, in C++ standars you use #include <iostream> and in C you use #include <stdio.h>. C++ standars say that you cant use libraries with .h but you can use them in C

Report •

Related Solutions

Ask Question