Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

compile error

I keep getting the error-
  no such file or directory
-concerning my iostream when i try to compile my c program.  Ive tried using std namesake and declaring iostream as a header file but still no luck.  Im pretty sure the libraries are installed
0
rlivings
Asked:
rlivings
  • 13
  • 11
  • 4
  • +1
1 Solution
 
munsieCommented:
are you using g++ to compile (vs. gcc)?

iostream is a c++ feature, not c.  also, make sure your filename extension is .cpp (or one of the various C++ extensions).

good luck,
dennis
0
 
rlivingsAuthor Commented:
this is my program
#include <iostream>

using namespace std;

int main()
{
  cout << "hello";
  return 0;
}

ive tried compiling with gcc and g++, the filename extension is .cc and it still does not work
0
 
zx9rCommented:
try to change the line:

#include <iostream>

by this one:

#include <iostream.h>
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rlivingsAuthor Commented:
tried that, nope
0
 
zx9rCommented:
write the following code and compile it with g++:

#include <iostream.h>

using namespace std;

int main()
{
       cout << "hello";
       return 0;
}


if it doesn´t work then you have to install de desired library
0
 
rlivingsAuthor Commented:
doesnt work zx9r, i guess i dont have the libraries installed.  someone posted a similar question recently and i checked to see if it was that using kpackage? im pretty sure i had it installed.  Ill try again thanks
0
 
rlivingsAuthor Commented:
I know i have the libraries for c and c++ files installed yet it still isnt recognized.   help anyone
0
 
jlevieCommented:
What Linux are you using and which compiler do you have? You can check the compiler with "cc -v".
0
 
zx9rCommented:
what is the error the compiler says?
0
 
rlivingsAuthor Commented:
my error is no such file or directory found (concering the iostream).  I am also using mandrake p-gcc and p-gcc-c++ I think it is called and i am not sure how to check the compiler using "cc -v".  Sorry, im really green i have experience as a user but installation and so forth , nada
0
 
jlevieCommented:
p-gcc/p-gcc-c++??? I don't use Mandrake, but those don't sound like a C or C++ compiler. I think you might not actually have a valid C/C++ development environment installed. Does "gcc -v" work and produce a version string? If that doesn't work either, try "rpm -q gcc". Looking at a Mandrake ftp site I can see that the distro includes gcc-2.95.2/gcc-c++-2.95.2 and if those are installed gcc ought to be how you'd invoke the compiler.
0
 
rlivingsAuthor Commented:
jlevie, i tried using the rpm -q gcc and it said package gcc is not installed.  I thought otherwise when i checked for the compilers using kpackage. Would you know how i could install them?
0
 
zx9rCommented:
como me parece que entiendes mejor el castellano, pues eso, te contestare en castellano :

a ver, lo primero es saber el nombre del paquete que quieres instalar, si no lo sabes puedes buscarlo con un ls *gcc* y mira los paquetes que hay.
Esto lo haces en el directorio donde estan todos los rpms (normalmente en el cd en RedHat/RPMS

luego lo instalas con rpm -iv paquete_que_quieres_instalar
0
 
jlevieCommented:
I think I might have an idea or two...

On your Mandrake installation CD I believe you'll find:

gcc-2.95.2-3mdk.i586.rpm
gcc-c++-2.95.2-3mdk.i586.rpm
gcc-cpp-2.95.2-3mdk.i586.rpm
libstdc++-2.95.2-3mdk.i586.rpm  

and some other gcc-* rpms. Since I don't use Mandrake I can't tell if there are other things that you'll need in addition to those (rpm/kpackage will tell you if they depend on others you've not installed). If not installed, you'll almost certainly want to add make-3.77-11mdk.i586.rpm to the list.

The easiest way to add them is with kpackage. Taking note of any that fail the dependancies check (and installing the dependant packages), then installing the package. You could also install them from the command line with "rpm -ivh /path-to/some.rpm", but kpackage will let you look at the description of what the package provides. That's helpful if you are trying to decide if you need it.
0
 
jlevieCommented:
I guess I shouldn't assume that you are using Mandrake 7.0. If it's an earlier version the exact version might be different. I'm looking at a Mandrake 7.0 ftp site for the package names.
0
 
rlivingsAuthor Commented:
thanks ill try that
0
 
jlevieCommented:
If you run into problems, post a comment here and I'll do what I can to help.
0
 
rlivingsAuthor Commented:
alright ive tried compiling a c program and i have no problem compiling and running it, but when it comes to c++ it cant find the iostream file.  Ive looked and i see the c libraries in the system environment? folder but the c++ libraries are in their own folder in a different location. maybe that is the problem?

Ron
0
 
jlevieCommented:
That seems odd, I would expect them to be in /usr/lib along with all of the other libraries. What exact compile command did you use and what's the directory path to libstdc++* files?
0
 
rlivingsAuthor Commented:
how do i find the directory path? and the compile command is g++ test.cc
0
 
jlevieCommented:
Try this from a shell window

find / -name "libstd*"

That compile command should have worked.
0
 
rlivingsAuthor Commented:
used the statement but it said file not found or something like that.   Using the xwindow i looked in the rpm package and in the submenu called development there is the c++ file which does not include c++ libraries but there is another submenu called libraries which has libstdc++.  Im thinking maybe i have to move the file or something i dont know.  thanks for your help anyway
0
 
jlevieCommented:
See if you've installed the libstdc++ libs with "rpm -q libstdc++". If they aren't yet installed you'll need to add that package. Also if they've been installed they should be in /usr/lib, check by "ls /usr/lib/libstdc++*".
0
 
rlivingsAuthor Commented:
alright jlevie tried to check and this is the output-
    /usr/lib/libstdc++ -libc6.1-1.so.2@
    /usr/lib/libstdc++.so.2.7.2@
    /usr/lib/libstdc++.so.2.7.2.8*
    /usr/lib/libstdc++.so.2.8@
    /usr/lib/libstdc++.so.2.8.0*
    /usr/lib/libstdc++.so.2.9@
    /usr/lib/libstdc++.so.2.9.0*
- which i assume means i have the libraries installed of course when i use the code way on the top, i still get the same error.  I was thinking about installing it again using GNOME RPM, but when i install the library it says failed to open /var/lib/rpm/packages.rpm
0
 
jlevieCommented:
You've got the libs installed, so it has to be something else. Make sure that your C++ file test.cc looks exactly like:

#include <iostream.h>

using namespace std;

int main()
{
    cout << "hello";
    return 0;
}

and compile it with the command:

g++ -o test test.cc

Copy everything that you see on the screen when you compile (including the compile command) into a comment so that I can see it, please.
0
 
rlivingsAuthor Commented:
okay i copied everything above in my test file and here is my prompt and commands:
[rlivings@localhost~]$g++ -o test test.cc

//the error is this:
test.cc:3:iostream.h: no such file or directory


that is it (the above is supposed to be on one line each but does not fit)
0
 
jlevieCommented:
Okay, now the problem is that the header files seem to be absent. I would have thought that they'd have been installed along with the compilers, but maybe not. On my Redhat system, iostream.h is in /usr/include/g++-2. The g++ compiler knows to look there for c++ headers.
0
 
rlivingsAuthor Commented:
so i have to check and see if i have the header files installed right?
0
 
jlevieCommented:
Yep. As I said, on Linux I'd normally expect to find them in /usr/include or one of it's sub-directories.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 13
  • 11
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now