~/Desktop/c++learning/quiz1> gcc -o num1 num1.cpp
/tmp/ccmz5SRA.o: In function `ReadNumber(void)':
num1.cpp:(.text+0x21): undefined reference to `cout'
num1.cpp:(.text+0x29): undefined reference to `ostream::operator<>(int &)'
/tmp/ccmz5SRA.o: In function `WriteAnswer(int)':
num1.cpp:(.text+0x70): undefined reference to `endl(ostream &)'
num1.cpp:(.text+0x8c): undefined reference to `cout'
num1.cpp:(.text+0x94): undefined reference to `ostream::operator<<(char const *)'
num1.cpp:(.text+0x9f): undefined reference to `ostream::operator<<(int)'
collect2: ld returned 1 exit status
I thought maybe I would try to installing the latest gcc from Haikuware. I did something wrong and so now gcc gives me this error
gcc: installation problem, cannot exec `cc1plus': No such file or directory
~/Desktop/c++learning/quiz1>
I just copied and pasted the solution so could someone tell me what went wrong after I am able to fix gcc?
that is C++ code not C code… so use g++ you may have to link the code with the libstdc++ if you are using gcc 2.9.5 otherwise g++ should work as you expect.
good heavens kidd106, you don’t need to re-install gcc
That error message is perfectly normal – your program is referencing stuff from iostream, and all that jazz is located in the standard C++ library (libstdc++), so you have to tell the linker to look in that library to resolve those references.
gcc -o num1 num1.cpp -lstdc++
that should work
Or, you could do as cb88 suggested and just use g++ (which is more convenient if you’re only compiling C++ sources).
What’s the difference between gcc and g++? Not much. AFAIK, g++ is pretty much the same program with a few additions in it that make compiling C++ sources easier.
“I was moving files around”…
You mean in /boot/develop/… where all the development tools are located?
Not a good idea. Would not recommend that. There’s too much interdependency about location and names of certain files. I would treat /boot/develop the same as /boot/system – i.e. look at the files, if you’re interested, but don’t muck with anything.
Haiku comes with gcc properly configured. If things are out of whack now, your best bet is to just reinstall Haiku. Go ahead and reinstall over your current Haiku partition. It won’t hurt anything. Afterwards, all the development tools will be where they’re supposed to be and you should be good to go.