compile error question
Claudio Bley
bley@mail.cs.uni-magdeburg.de
Thu Oct 11 18:56:00 GMT 2001
>>>>> "Jim" == Jim M <msg124@hotmail.com> writes:
Jim> I try this with "gcc myfile.c -o myfile" i get the iostream.h not
Jim> found. If i do "gcc myfile.C -o myfile" i get the "storage size of
Jim> 'cube' is not known. ..redefinition of 'char *cube[]".. thanks, J
Jim> #include <iostream.h> char *cube[]; int main() { int i; while (0)
Jim> { i = 0; while (cube[i]){ cout << cube[i++]; } } }
Jim> char* cube[] = {"\n\ ____\n\ / /|\n\ /___/ |\n\ | | /\n\
Jim> |___|/\n",
Jim> "\ ___\n\ | |\n\ |___|\n\ | |\n\ |___|\n",
Jim> "\ ____ \n\ |\\ \\ \n\ | \\___\\ \n\ \\ | | \n\ \\|___| \n",
Jim> "\ /\\ \n\ / \\ \n\ |\ /| \n\ | \/ | \n\ \\ | / \n\ \\|/ \n",
Jim> NULL };
Jim> _________________________________________________________________
Jim> Get your FREE download of MSN Explorer at
Jim> http://explorer.msn.com/intl.asp
I don't know whether somebody already told you - and it can be sometimes
confusing ;-), but you're writing in C++ mode, just use the C++ compiler
backend: g++
$ g++ -o myfile myfile.C
As you could have easily looked up in the man page of gcc it is
substantially which file extension you choose for your source file - or you
have to specify which language gcc should expect.
To quote the manual:
.c C source; preprocess, compile, assemble
.C C++ source; preprocess, compile, assemble
.cc C++ source; preprocess, compile, assemble
As you can see .C implies that your file contains C++ code - .c does not
and that's why you are getting the first error.
Additionally, you should use #include <iostream> (without the .h unless you
know that you explicitely need the .h file).
Then, you can't declare cube twice - this is NOT allowed. You just want to
say that theres somewhere a variable of a specific type, so you need to
declare cube extern in the first instance:
extern char* cube[];
Also, you should use double backslashes in strings globally in order to
express one single backslash (I got unknown escape sequence errors). And,
maybe it's only a matter of style but I initialise string arrays like this:
char *cube[] = {"\n"
" 1st line \n"
" 2nd line \n", NULL };
I think it's better than escaping newlines (I also got unknown escape
sequence errors on some of your line breaks).
HTH
Claudio
More information about the Gcc-help
mailing list