Compiling help???

This is a discussion on Compiling help??? within the Linux Programming forums, part of the Platform Specific Boards category; Hi all, how do i compile a c++ program in linux??? i am using ubuntu and i have the g++ ...

  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,211
    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
    22,181
    How does it not work?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,767
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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
    22,181
    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
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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
    22,181
    Aye, you may wish to read or at least bookmark the GCC documentation for future reference.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 12:23 PM
  2. Problem compiling files that store functions
    By tiachopvutru in forum C++ Programming
    Replies: 10
    Last Post: 05-30-2008, 06:42 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Compiling in Unix vs Visual C++
    By stimpyzu in forum C++ Programming
    Replies: 2
    Last Post: 09-30-2002, 07:41 AM
  5. Compiling syntax
    By Jez_Master in forum C++ Programming
    Replies: 3
    Last Post: 04-01-2002, 09:46 PM

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