help with gcc
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: help with gcc

  1. #1
    Member
    Join Date
    Jun 2003
    Posts
    86

    help with gcc

    Ive been programming in c++ for a while and when i swiched to linux i didnt like any of the programming interfaces, so i wanted to learn to do it in command line. I cannot get ANY programs to work with ANYTHING on linux in C++. Please help!!!!
    (yes i know i am a newbie)
    You laugh because im different, i laugh because your all the same.

  2. #2
    Senior Member
    Join Date
    Oct 2002
    Posts
    1,130
    The command you need is

    gcc <source file> -o (output file)

    To run the compiled file the command is

    ./<filename>

    Don't forget the "./". I do not believe Linux will check the default directory for the filename you specify. You have to tell it where to look, unless it's specified in your path. I know RedHat does that.
    Government is like fire - a handy servant, but a dangerous master - George Washington
    Government is not reason, it is not eloquence - it is force. - George Washington.

    Join the UnError community!

  3. #3
    Senior Member
    Join Date
    Jul 2002
    Posts
    117
    To compile C++ programs under Linux, usually you can do so with gcc. From the command line, just type "gcc <program name>" (without the quotes of course). If you need other compilation options, check out the man page, "man gcc".

    Hope this helps,
    alpha

  4. #4

  5. #5
    Member
    Join Date
    Jun 2003
    Posts
    86
    its for some reason coming up w/ a compile error ive never seen before... Whats wrong with this source:
    #include <iostream.h>
    int main()
    {
    cout << "Hello, World!";
    return 0;
    }
    You laugh because im different, i laugh because your all the same.

  6. #6
    Senior Member
    Join Date
    Oct 2002
    Posts
    1,130
    A little more detail here might help. You're basically asking us to fix a leaky basement without telling us where the leak is.
    What errors are you getting?
    Government is like fire - a handy servant, but a dangerous master - George Washington
    Government is not reason, it is not eloquence - it is force. - George Washington.

    Join the UnError community!

  7. #7
    Senior Member
    Join Date
    Jul 2002
    Posts
    117
    ummm... what's the error??

  8. #8
    Member
    Join Date
    Jun 2003
    Posts
    86
    the errors are as follows:
    undefined refrence to "std::cout"
    undefined refrence to "std::basic_ostream <a bunch of vars passed through this arg.>
    undefined refrence to "std::iso_base::Init::~Init [in-charge]()"
    undefined refrence to "__gxx_personality_v0"
    and then it says:
    collect2: ld returned 1 exit status
    You laugh because im different, i laugh because your all the same.

  9. #9
    Senior Member
    Join Date
    Oct 2002
    Posts
    1,130
    Try including the line

    using namespace std;

    Your code would look like this:

    #include <iostream.h>
    using namespace std;
    int main()
    {
    cout << "Hello, World!";
    return 0;
    }

    You haven't defined a nemaspace which includes the cout stream yet.
    Hope this helps.

    /edit
    Some compilers add namespaces by default if you don't tell them to. The Gnu C compiler doens't, but it's free, so I never complain about it.
    /edit
    Government is like fire - a handy servant, but a dangerous master - George Washington
    Government is not reason, it is not eloquence - it is force. - George Washington.

    Join the UnError community!

  10. #10
    Member
    Join Date
    Jun 2003
    Posts
    86
    Striek:
    i just tried that... no luck.
    You laugh because im different, i laugh because your all the same.

Posting Permissions

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