Compiling a program

Hello. I am trying to run a c program on a unix shell (ssh). I have searched this forum but have not come accross the soultion to my problem, so I am posting my question here :cool:

I wrote the following simple code:

#include <iostream.h>

using namespace std;

int main()
{
cout << "\nThis is our first C++ prgram.";
cout << "\nIt works!!!";

    return 0;

}

I saved this in a file called first.c
I entered command gcc first.c
I get error "first.c:1: iostream.h: No such file or directory"
I dont understand, does the gcc compiler not come with standard headers such as iostream and iomanip?

Minnesota Red,

I'm not sure if this would solve your problem, but check your LD_LIBRARY_PATH. This would be different depending on your OS. It seem to me that your "env" variable may not include the system standard library path. Try > env|grep LIBRARY, then chek each directory to see if the library is there. You may just be missing the library in general. If on a linux platform try >locate ipstream.h. If you get a result then that mean you have some other problem.

Larry

OS is winxp, but I am using ssh to compile. I dont know if that makes much difference. I am a newbie, so I did not follow what you were saying.

BTW, Mod can U move this to correct forum. I just realized I posted this in wrong area by accident.

(Moved)

Your shell has variables set (seen with the env command). One of them is the LD_LIBRARY_PATH. You need to find where the file iostream.h is located and add that directory path to your LD_LIBRARY_PATH.

# echo $LD_LIBRARY_PATH
/usr/lib:/usr/local/lib:/usr/openwin/lib

(Ours is set up in a second profile)
# . /u/etc/profile
Profile Rev: v1.2.0.4 Platform: SunOS Architecture: sun4u
Initializing: ................ Done.
#
# echo $LD_LIBRARY_PATH
LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib:/u/lib:/usr/ccs/lib:/usr/5bin/lib:/usr/ucblib:/usr/xpg4/lib:/u/lib:/usr/openwin/server/lib:/usr/openwin/lib:/usr/opt/SUNWmd/lib

So the OS is Debian Linux, not WinXP - the Linux system is where you are compiling, correct?

To find the file, you can ask the Sys Admin, or try using the find command (man find) - it may be in /usr or /u (it matters how the system is set up).

And honest too.

You have written a c++ program, not a c program.

Try this command

g++ first.c -o first

to compile it. You have a bug, but I'll let you find it.

u sure? this is str8 out the text book

btw, the g++ worked. THANX!

how do I go about executing the a.out that I now have?

Your output file is called first. You can run it with "./first".

Use your own good judgement as you view the results.

Yah I just found that browsing another site. THANX A LOT FOR HELP. I am finally seeing how c++, with unix, with a database tie in... its all coming together.

So my college degree wasnt a total waste, was it :smiley: ?