|
FreeBSD General Other questions regarding FreeBSD which do not fit in any of the categories below. |
|
Thread Tools | Display Modes |
|
|||
Why wont this compile?
Hi,
Well over the past few weeks this newbie has been very impressed over FreeBSD and wonders why he wasted years with M$ products. Your support has been wonderfull and the O/S rocks. However being a programmer at heart I wanted to check out gcc++. So I made a file Hello.cpp Code:
#include <iostream> int main() { cout << "Hello World\n"; return 0; } Code:
/var/tmp//ccPEm5DG.o(.text+0x1e): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': : undefined reference to `std::string::size() const' /var/tmp//ccPEm5DG.o(.text+0x69): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': : undefined reference to `std::string::operator[](unsigned int) const' /var/tmp//ccPEm5DG.o(.text+0xa7): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': : undefined reference to `std::string::operator[](unsigned int) const' /var/tmp//ccPEm5DG.o(.text+0xef): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': : undefined reference to `std::string::operator[](unsigned int) const' /var/tmp//ccPEm5DG.o(.text+0x13c): In function `main': : undefined reference to `std::cout' /var/tmp//ccPEm5DG.o(.text+0x141): In function `main': : undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' /var/tmp//ccPEm5DG.o(.text+0x17d): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `std::ios_base::Init::Init()' /var/tmp//ccPEm5DG.o(.text+0x1ce): In function `__tcf_0': : undefined reference to `std::ios_base::Init::~Init()' /var/tmp//ccPEm5DG.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' $ /var/tmp//ccPEm5DG.o(.text+0x1e): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': : undefined reference to `std::string::size() const' /var/tmp//ccPEm5DG.o(.text+0x69): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': : undefined reference to `std::string::operator[](unsigned int) const' Syntax error: word unexpected (expecting ")") /var/tmp//ccPEm5DG.o(.text+0xa7): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': $ : undefined reference to `std::string::size() const' /var/tmp//ccPEm5DG.o(.text+0x69): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': : undefined reference to `std::string::operator[](unsigned int) const' /var/tmp//ccPEm5DG.o(.text+0xa7): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': : undefined reference to `std::string::operator[](unsigned int) const' /var/tmp//ccPEm5DG.o(.text+0xef): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': > /var/tmp//ccPEm5DG.o(.text+0x69): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': Syntax error: "(" unexpected $ : undefined reference to `std::string::operator[](unsigned int) const' > /var/tmp//ccPEm5DG.o(.text+0xa7): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': Syntax error: word unexpected (expecting ")") Syntax error: word unexpected (expecting ")") $ : undefined reference to `std::string::operator[](unsigned int) const' > /var/tmp//ccPEm5DG.o(.text+0xef): In function `std::__verify_grouping(char const*, unsigned int, std::string const&)': Syntax error: word unexpected (expecting ")") Syntax error: word unexpected (expecting ")") $ : undefined reference to `std::string::operator[](unsigned int) const' > /var/tmp//ccPEm5DG.o(.text+0x13c): In function `main': Syntax error: word unexpected (expecting ")") > : undefined reference to `std::cout' main: : undefined reference to `std::cout: not found $ /var/tmp//ccPEm5DG.o(.text+0x141): In function `main': Syntax error: word unexpected (expecting ")") $ : undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' > /var/tmp//ccPEm5DG.o(.text+0x17d): In function `__static_initialization_and_destruction_0(int, int)': Syntax error: redirection unexpected Syntax error: word unexpected (expecting ")") $ : undefined reference to `std::ios_base::Init::Init()' > /var/tmp//ccPEm5DG.o(.text+0x1ce): In function `__tcf_0': > : undefined reference to `std::ios_base::Init::~Init()' $ /var/tmp//ccPEm5DG.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' Thanking you in advance, Jonathan. |
|
|||
Or, instead.. do:
Code:
// test.cc or test.cpp #include <iostream> using namespace std; int main(void) { cout << "Hello World\n"; return 0; } Anyway, I don't understand why people use C++ instead of C.. it's so much cleaner. |
|
||||
1) I don't discourage others ... only the ones who work with me
2) I do not want to start a troll pros/cons c++ I only said that I agree with BSDfan666. I have spent 9 months debugging a huge C++ hugly code, because the language is too much complicated for novices. C is far more simpler (powerless ? I do not think so) I may speak about malloc/new, references, exceptions and so on... "How C++ is like teenage sex: 1. It is on everyone's mind all the time. 2. Everyone talks about it all the time. 3. Everyone thinks everyone else is doing it. 4. Almost no one is really doing it. 5. The few who are doing it are: A. Doing it poorly. B. Sure it will be better next time. C. Not practising it safely."
__________________
-- Nicolas |
|
||||
> I have spent 9 months debugging a huge C++ hugly code, because the language is too much complicated for novices.
yes i agree C++ is a complicated prog. language. > "How C++ is like teenage sex: ... Not practising it safely." i hope you didn't miss the context of that joke. it was a toilet graffiti in the CS dept. of a college in Israel way back in 1993 (i suppose C++ must have been the over-hyped latest programming fad at the time). Last edited by ephemera; 19th May 2008 at 10:57 PM. |
|
|||
Okay it now works...
ephemera had most of the answer, I was using the wrong compiler. I should use g++ not anything else, but then I ran into a problem.
So g++ -o Hello Hello.cpp worked with the following code. Code:
#include <iostream> using namespace std; int main() { cout<<"Hello World\n"; return 0; } The thing wouldn't execute from the current directory so Code:
Hello Code:
./Hello Thanks for your help guys, in future I will post programming questions where they belong. Cheers, Jonathan. |
|
||||
Code:
#include <iostream> Although you might find a compiler that barfs about missing .h's you probably will never find one that complains by default about them. I believe one of the changes in the transition from Qt3 to Qt4 is #include <QWhatEver> is now the preferred norm as well over the old #include <QWhatEver.h> or die. (Disclaimer: I have avoided using C++ for a long time now, I prefer ISO/IEC 9899:1999 aka C99 ). If one doesn't need access to much of the (entire) std namespace it's probably best to do something else in a larger (more realistic) program, but I think everyone here knows that and I use helloworlds to test new compilers/IDE's as well The name spaces related syntax and templates are one of the very few things that I like about C++. Quote:
If $PATH is == /bin:/usr/bin typing 'hello' tells the shell to look for /bin/hello and then /usr/bin/hello. If you don't like doing the ./hello thing you'll have to add the current working directory to your shells $PATH.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
pidgin (py25-gtk) wont upgrade | mururoa | FreeBSD Installation and Upgrading | 3 | 7th September 2009 07:45 PM |
Epiphany and Firefox2 wont update | delboy | FreeBSD Ports and Packages | 4 | 25th August 2009 01:18 PM |
Firefox 3 port wont compile : libsoftokn3.so problems | padmanabh | FreeBSD Ports and Packages | 3 | 8th October 2008 07:13 AM |
PF wont open port despite rules... | Dain_L | OpenBSD Security | 3 | 12th September 2008 01:14 AM |
KDE wont start up | dctr | FreeBSD General | 9 | 11th June 2008 05:59 AM |