Click to See Complete Forum and Search --> : Not sure if g++ is installed correctly
lombardp
03-29-2001, 10:24 PM
I got this snipplet of code (see bottom) from www.cplusplus.com (http://www.cplusplus.com) and I tried to compile it on my machine I got a ton of compiling errors. I telneted to a server here at Purdue and successfully compiled this little program and it ran great. It might be of how I installed the header files that come with iostream.h. I went and downloaded the rpms and installed them, but my g++ compiler still wouldn't find the header files I needed to compile my programs because they were in /usr/include/g++-2. I copied all of them over to /usr/include and although I get a warning, simple programs will still compile. I know I did something wrong but I'm not sure what or how to go about fixing it. Any thoughts? By chance when you install g++ does it search for the header files on your system and where they're located? I installed g++ awhile ago and the package with iostream.h today. Just a thought.
// classes example
#include <iostream.h>
class CRectangle {
int x, y;
public:
void set_values (int,int);
int area (void) {return (x*y);}
};
void CRectangle::set_values (int a, int b) {
x = a;
y = b;
}
int main () {
CRectangle rect;
rect.set_values (3,4);
cout << "area: " << rect.area();
}
[ 29 March 2001: Message edited by: lombardp ]
Bradmont
03-29-2001, 10:29 PM
Try removing the ".h" from "iostream.h". In the newer c++ specs, it's not needed (and not desired). That might help.
lombardp
03-29-2001, 10:52 PM
I took the .h out of it and got the same errors. This is what the compiler told me:
In file included from /usr/include/iostream.h:31,
from /usr/include/iostream:6,
from CRectangle.cpp:1:
/usr/include/streambuf.h: In method `ios::~ios()':
/usr/include/streambuf.h:485: warning: `void *' is not a pointer-to-object type
CRectangle.cpp: At top level:
CRectangle.cpp:11: syntax error before `::'
CRectangle.cpp:13: ANSI C++ forbids declaration `y' with no type
CRectangle.cpp:13: `b' was not declared in this scope
CRectangle.cpp:14: parse error before `}'
CRectangle.cpp: In function `int main()':
CRectangle.cpp:17: `CRectangle' undeclared (first use this function)
CRectangle.cpp:17: (Each undeclared identifier is reported only once
CRectangle.cpp:17: for each function it appears in.)
CRectangle.cpp:17: parse error before `;'
CRectangle.cpp:18: `rect' undeclared (first use this function)
Thoughts?
Bradmont
03-29-2001, 11:04 PM
Hrms... I just c&p'd the code, tried it and it worked fine... The code referrenced in your error messages (from the iostream header file) seems to make no sense... void * would be trying to declare a pointer to a void... which can't be done, as there is no such thing as a void (as a data type, that is). My guess would be there is some error in the way you've got your headers installed. What it is is what I couldn't tell you... you might want to try a reinstall (of the c++ libraries). Good luck, and sorry I couldn't be more help :(.
sans-hubris
03-30-2001, 03:50 AM
update libstdc++ (there's a link at http://gcc.gnu.org ). Many of the older libraries were very buggy.
lombardp
03-30-2001, 10:51 AM
I updated the libstdc++ and it got rid of those warnings that I was getting at the beginning but I still have all the compilation errors. I would guess it is g++ that has to be fixed then. Hm... :(