Find the answer to your Linux question:
Results 1 to 7 of 7
i tried search but not sure what to search for. i'm a c++ and linux noob. so the error message is meaningless to me =D i looked into man gcc. ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2004
    Posts
    34

    using gcc :(


    i tried search but not sure what to search for.

    i'm a c++ and linux noob. so the error message is meaningless to me =D

    i looked into man gcc. but it's just a bunch of options i didnt understand

    i've used devC++ on windows. but now i am more on linux so i read somwhere there's this gcc thing.

    i did

    $ gcc 1.cpp

    1.cpp being
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main&#40;&#41;
    &#123;
    
      cout << "Hello World";
    
      return 0;
    
    
    &#125;
    it gives this error

    /tmp/ccmcVrNr.o(.text+0x19): In function `main':
    : undefined reference to `std::cout'
    /tmp/ccmcVrNr.o(.text+0x1e): 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*)'
    /tmp/ccmcVrNr.o(.text+0x4a): In function `__static_initialization_and_destruction_0(int, int)':
    : undefined reference to `std::ios_base::Init::Init[in-charge]()'
    /tmp/ccmcVrNr.o(.text+0x79): In function `__tcf_0':
    : undefined reference to `std::ios_base::Init::~Init [in-charge]()'
    /tmp/ccmcVrNr.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
    collect2: ld returned 1 exit status

    is it the extension or some option i need to use for C++ scripts?

    thank you

  2. #2
    Linux User
    Join Date
    Jul 2004
    Posts
    256
    gcc is the c compiler. g++ is the c++ compiler. (It actually calls gcc, 'tells it to compile c++')

    You want this
    Code:
    g++ -o binary source.cpp
    Where binary is the binary, and source.cpp is your source.
    --monkey

  3. #3
    Linux Enthusiast Opnosforatou's Avatar
    Join Date
    Dec 2003
    Location
    Vleuten, The Netherlands
    Posts
    552
    Code:
    #include <iostream>
    int main&#40;&#41;
    &#123;
    	std&#58;&#58;cout << "Hello world" << std&#58;&#58;endl;
    	return 0;
    &#125;
    This should work
    ---[ MS09-99896 - Vulnerability in All MS Windows OS ; Using Windows Could Allow Remote Code Execution. ]---
    Hardware: Asus P4P800, 1GB, P4-3Ghz, Asus V9950, Maxtor ATA HD\'s, 3Com GBit lan, Audigy ZS Plat.

  4. #4
    Linux User
    Join Date
    Jul 2004
    Posts
    256
    His code will work if he compiles with g++. Your code won't work if you tried to compile using gcc.
    --monkey

  5. #5
    Just Joined!
    Join Date
    Jun 2004
    Posts
    34
    oh. cause man gcc said it's for both. i guess it is just in a different ways

    thanks =)

  6. #6
    Linux User
    Join Date
    Jul 2004
    Posts
    256
    Quote Originally Posted by prey
    oh. cause man gcc said it's for both. i guess it is just in a different ways

    thanks =)
    It's probably because g++ actually calls gcc, but with special flags
    --monkey

  7. #7
    Just Joined!
    Join Date
    May 2004
    Posts
    34
    Quote Originally Posted by monkey8
    Quote Originally Posted by prey
    oh. cause man gcc said it's for both. i guess it is just in a different ways

    thanks =)
    It's probably because g++ actually calls gcc, but with special flags
    Yes you can use gcc to compile c,c++, even java but you need the right flags otherwise default compilation will start with C.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •