Thread: Compiling help???

  1. #1
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115

    Compiling help???

    Hi all, how do i compile a c++ program in linux??? i am using ubuntu and i have the g++ compiler installed...

    Please help???

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Something like this:

    Code:
    g++ bleh.cpp

  3. #3
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    i tried that, it didn't work..... what i am working on a program to help me clean and sort out and merge my word lists for pentesting...

    now i dont know if it will work at all as i have never tried to program anything in linux before...
    Code:
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        string temp[100];
        ifstream wordlist_in;
    
        wordlist_in.open (argv[1]);
    
        if (wordlist_in.is_open())
        {
            for (int i=0;;i++)
            {
                getline (wordlist_in, temp[i]);
                cout << temp[i] << endl;                    
                if (wordlist_in.eof())
                {
                   break;
                }
           }
        }
    
        return EXIT_SUCCESS;
    }
    that is what i have done so far, as im sure you know all it dose is take the words from a file name pass from argv and display them... but as i am new to programing in linux, i am vary lost...

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    How does it not work?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Post your console log as well, showing how you compiled it as well.

    Perhaps you're confused as to how to run the result?
    In which case, try typing this at your command prompt after compiling
    ./a.out myfile.txt
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    Quote Originally Posted by laserlight View Post
    How does it not work?
    Well i know the code i have so far works fine, because what i have done so far i have done in windows... where i have compiled it and run it...

    where i am getting confused is how do i do it in linux... i run the command g++ WordList.cpp it dose something for a while, and then nothing changes... i know in linux there isn't ".exe" file... so when i run the g++ command where is my program compiled and placed? How do i get at it????? :S

  7. #7
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    Quote Originally Posted by Salem View Post
    Post your console log as well, showing how you compiled it as well.

    Perhaps you're confused as to how to run the result?
    In which case, try typing this at your command prompt after compiling
    ./a.out myfile.txt
    ok, when i run ./a.out it runs my program.... Thanks heaps for that, but where exactly do you get ./a ???

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    where i am getting confused is how do i do it in linux... i run the command g++ WordList.cpp it dose something for a while, and then nothing changes... i know in linux there isn't ".exe" file... so when i run the g++ command where is my program compiled and placed? How do i get at it????? :S
    MacGyver's example will produce a file named a.out that you can run from the command line. If you want a more appropriate name for the executable program, you can write:
    Code:
    g++ -o executable source.cpp
    Then run it, e.g.,
    Code:
    ./executable
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    ah ok, thanks heaps... i only just made the switch from windows to linux.... and there are so many things i have to start learning again...

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Aye, you may wish to read or at least bookmark the GCC documentation for future reference.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie Compiling Problem
    By Deronius in forum C++ Programming
    Replies: 3
    Last Post: 06-15-2008, 11:23 AM
  2. Problem compiling files that store functions
    By tiachopvutru in forum C++ Programming
    Replies: 10
    Last Post: 05-30-2008, 05:42 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Compiling in Unix vs Visual C++
    By stimpyzu in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2002, 06:41 AM
  5. Compiling syntax
    By Jez_Master in forum C++ Programming
    Replies: 3
    Last Post: 04-01-2002, 09:46 PM