LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Can't compile c++ program (https://www.linuxquestions.org/questions/programming-9/can%27t-compile-c-program-66147/)

eg_wwkaa 06-17-2003 10:45 AM

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.

jvannucci 06-17-2003 11:28 AM

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`

eg_wwkaa 06-17-2003 11:41 AM

Dear Jvannucci,

Yes, the command return the name of the package that you mention. So, do you know what is going wrong?

jvannucci 06-17-2003 12:00 PM

No, sorry. I suspected that you hadn't properly installed the iostream headers.

eg_wwkaa 06-17-2003 12:08 PM

Yes, I think so too.
So, what would you sugguest to do???
Remove and Re-Install this package???
and how?

jvannucci 06-17-2003 12:19 PM

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

mrtwice 06-17-2003 12:28 PM

are you compiling with the gcc command instead of g++. If you are, you will get errors like that.

eg_wwkaa 06-17-2003 08:51 PM

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?

eg_wwkaa 06-17-2003 08:52 PM

Dear mrtwice,

So strange? So, what is wrong with the syntax from the point of view of gcc?

jvannucci 06-17-2003 09:01 PM

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.

eg_wwkaa 06-17-2003 09:26 PM

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.

eg_wwkaa 06-17-2003 09:30 PM

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?

GtkUser 06-18-2003 01:33 AM

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

eg_wwkaa 06-18-2003 02:32 AM

-lstdc++ indicate the library name?

andox 06-18-2003 02:36 AM

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.