Results 1 to 5 of 5

Thread: What do I need to compile a cpp file?

  1. #1
    Join Date
    Apr 2006
    Location
    Beijing
    Beans
    3
    Distro
    Kubuntu Breezy 5.10

    What do I need to compile a cpp file?

    My source code is faily simple as below:

    #include<iostream>

    using namespace std;

    int main(void)
    {
    cout<<"Hello World!"<<endl;
    return 0;
    }


    But compiler gave me some error messages like this:
    /tmp/ccNfUm8H.o: In function `main':
    1.cpp.text+0x25): undefined reference to `std::cout'
    1.cpp.text+0x2a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
    ...........

    I used cpp to compile my code, is it the right thing to compile C++ files?
    thx a lot!

  2. #2
    Join Date
    Mar 2005
    Location
    Reading, UK
    Beans
    25

    Re: What do I need to compile a cpp file?

    Code:
    gcc <filename> -lstdc++
    ought to do it...

  3. #3
    Join Date
    Dec 2005
    Beans
    164
    Distro
    Ubuntu 6.06 Dapper

    Re: What do I need to compile a cpp file?

    you can also try
    Code:
    g++ <filename>

  4. #4
    Join Date
    Apr 2006
    Location
    Beijing
    Beans
    3
    Distro
    Kubuntu Breezy 5.10

    Re: What do I need to compile a cpp file?

    god....can't start X now....

  5. #5
    Join Date
    Jul 2005
    Beans
    1,535
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: What do I need to compile a cpp file?

    Can't help you with X, but to compile make sure you have build-essential installed
    Code:
    sudo apt-get install build-essential
    and then simply type
    Code:
    g++ file.cpp
    When I invented the Web, I didn't have to ask anyone's permission.
    ~Tim Berners-Lee on Net Neutrality
    -------------------------------------
    Visit the Ubuntu Programming IRC-channel at #ubuntu-programming (chat.freenode.net).

Bookmarks

Posting Permissions

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