strange errors when compiling.

This is a discussion on strange errors when compiling. within the C++ Programming forums, part of the General Programming Boards category; Hi folks, I am new to this forum. Am 25 years old, I am working in the computer-area for about ...

  1. #1
    registered citizen twilight's Avatar
    Join Date
    Aug 2009
    Location
    Germany
    Posts
    23

    strange errors when compiling.

    Hi folks,

    I am new to this forum. Am 25 years old, I am working in the computer-area for about 9 years now (if you count my aprenticeship) but never got the hang of programming myself.

    Sure, I had the basics about C and Java2 and stuff, but never really got over that.

    So I thought I'd start with programming anew, and found this site.

    When I try to compile the first Program of the first lesson:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
      cin.get();
    }
    I get a strange error.

    This is what I do:

    - type the above with nano on the command-line (am on MacOSX now, but I did this with Linux too to confirm the error)
    - save it as hello.cpp
    - exit nano
    - execute "gcc hello.cpp" or "gcc hello.cpp -o hello"
    - I get the following:

    Code:
    bash-3.2$ gcc hello.cpp 
    Undefined symbols:
      "___gxx_personality_v0", referenced from:
          ___gxx_personality_v0$non_lazy_ptr in cciNlgWN.o
      "std::basic_istream<char, std::char_traits<char> >::get()", referenced from:
          _main in cciNlgWN.o
      "std::ios_base::Init::~Init()", referenced from:
          ___tcf_0 in cciNlgWN.o
      "std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
          _main in cciNlgWN.o
      "std::ios_base::Init::Init()", referenced from:
          __static_initialization_and_destruction_0(int, int)in cciNlgWN.o
      "std::cin", referenced from:
          __ZSt3cin$non_lazy_ptr in cciNlgWN.o
      "std::cout", referenced from:
          __ZSt4cout$non_lazy_ptr in cciNlgWN.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    bash-3.2$
    What seems to be the problem??

    I simply have no clue whatsoever!

    Thx for any help, will be apreciated!

    twilight

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    You need to run g++ hello.cpp.

    Your code is C++, not C. gcc is the C compiler, g++ is the C++ compiler.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    registered citizen twilight's Avatar
    Join Date
    Aug 2009
    Location
    Germany
    Posts
    23
    I feel kind of stupid now because I usualy know stuff like that.

    Used to use Gentoo-Linux for years and compiling sources and whatnot... :-D

    thx, that was it.

  4. #4
    The Programming Dutchman
    Join Date
    Jan 2008
    Posts
    55
    does your int main() function return nothing?

    i think it have to look like this:

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
      cin.get();
      return 0;
    }
    good luck!

    Jelte,
    The Programming Dutchman

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    does your int main() function return nothing?

    i think it have to look like this:
    No, C++ implicitly returns 0 from main() if there is no explicit return statement. His code is correct as it is.
    bit∙hub [bit-huhb] n. A source and destination for information.

  6. #6
    The Programming Dutchman
    Join Date
    Jan 2008
    Posts
    55
    @bithub ok. nice to know
    The Programming Dutchman

  7. #7
    registered citizen twilight's Avatar
    Join Date
    Aug 2009
    Location
    Germany
    Posts
    23
    yeah, the code should be ok. It is the one right from the tutorial :-D

    but thx for your reply! As I said before: it is alright now! Using g++ instead of gcc it worked.

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,790
    Do not blindly rely on tutorials, however. A lot of them spew out bad practices.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,511
    like:

    using namespace std;
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling errors
    By courtesan in forum C Programming
    Replies: 2
    Last Post: 08-18-2005, 10:52 AM
  2. help with strange errors
    By rockdj in forum C++ Programming
    Replies: 4
    Last Post: 07-27-2004, 11:42 AM
  3. opengl Nehe tutorial errors when compiling
    By gell10 in forum Game Programming
    Replies: 4
    Last Post: 07-14-2003, 08:09 PM
  4. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 03:00 PM
  5. stupid errors i got after compiling!! HELP ME!
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2001, 04:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21