Can't compile c++ program
I have just installed Red Hat 9.
I haven't installed any development tools include gcc in the installation time. However, I install gcc and other development tools using the GUI program "add/remove program" in X windows after Red Hat is successfully installed. However, I got error when compiling the following code: /****************** Start of Code ******************/ #include <iostream> using namespace std; int main() { cout << "Hello World" << endl; return 0; } /****************** End of Code ******************/ /**************** Error Message ******************* a.cpp:1:20: iostream: 沒有此一檔案或目錄 a.cpp: In function `int main()': a.cpp:4: `cout' undeclared (first use this function) a.cpp:4: (Each undeclared identifier is reported only once for each function it appears in.) a.cpp:4: `endl' undeclared (first use this function) ****************************************************/ Notes: I am using Chinese as default language, so, you may found some character is not able to display. But that words mean "file or directory not found" Your kindly help is appreciated if this problem can be solved. Thank you very much. |
Do you have the following packages installed?
libstdc++-devel-3.2.2-5 compat-libstdc++-devel-7.3-2.96.118 # rpm -qf `find /usr/include -name iostream` |
Dear Jvannucci,
Yes, the command return the name of the package that you mention. So, do you know what is going wrong? |
No, sorry. I suspected that you hadn't properly installed the iostream headers.
|
Yes, I think so too.
So, what would you sugguest to do??? Remove and Re-Install this package??? and how? |
Well, I guess you could try that. First I'd list the files that the packages install and see if the 'interesting files' exist in their proper locations.
# rpm -qlp libstdc++-devel-3.2.2-5 # rpm -qlp compat-libstdc++-devel-7.3-2.96.118 Perhaps compare with: # rpm -ql libstdc++-devel # rpm -ql compat-libstdc++-devel |
are you compiling with the gcc command instead of g++. If you are, you will get errors like that.
|
Dear jvannucci,
Really thanks for you big hand, I am now in my office, I will try it tonight. But how if these packages exist? |
Dear mrtwice,
So strange? So, what is wrong with the syntax from the point of view of gcc? |
I'm right here, so I'll answer, if that's OK. gcc is the C compiler. g++ is the C++ compiler. iostream is a C++ header.
This may well fix all your problem. |
Dear jvannucci and mrtwice,
Really hundreds and thousands thankx to you! That's why when I write a C "Hello World" program by using "stdio.h", gcc can compile, where as, when using <iosteam>, it got error! Anyway, let me try it out tonight and see if it works with g++, hope you would kindly help me again if problem still exists. Thank you very much. |
According to http://gcc.gnu.org/
It says: GCC is the GNU Compiler Collection, which currently contains front ends for C, C++, Objective-C, Fortran, Java, and Ada, as well as libraries for these languages (libstdc++, libgcj,...). Doesn't it compiles C++ too? |
You can compile a C++ program with gcc like this:
gcc program.cpp -lstdc++ ./a.out However it's eaiser to just do: g++ program.cpp ./a.out |
-lstdc++ indicate the library name?
|
hi im getting the same problems when i try to compile too.. im also new at linux and im not sure of what to do.. even after i read the above im still a lil ocnfused.. where do i get these packages?
|
All times are GMT -5. The time now is 04:45 PM. |