Find the answer to your Linux question:
Results 1 to 3 of 3
Hello everyone (first post!) I've recently found a lot of time on my hands, so i've decided to learn C++. Unfortunately, i've run into a few problems with the very ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Aug 2011
    Posts
    38

    C++ programming intro


    Hello everyone (first post!)

    I've recently found a lot of time on my hands, so i've decided to learn C++.

    Unfortunately, i've run into a few problems with the very first example program.

    I've called the program "Sample.cpp", and i'm able to get it to compile and run using:

    g++ Sample.cpp -o Sample -Wall
    ./Sample

    ...and I get the familiar "Hello World!" output.

    In the directory, I have a file called "Sample.cpp" and a new file called "Sample" that doesn't have a file extension.

    However, I don't really know what i've just done.

    I have a few questions:

    1). What does "-o" in the compiling line mean?
    2). What does "-Wall" in the compiling line mean?
    3). What is the file extension of "Sample"? (I'm used to Latex, where the file goes from a .tex ---> .dvi ---> .pdf ie. there is always a file extension).

    If anyone could help me with these questions, it would be great.

  2. #2
    Linux Newbie
    Join Date
    Jul 2007
    Location
    Here. There. Anywhere.
    Posts
    157
    The -o switch allows you to name the output file. By default GCC outputs a binary file called "a.out" but with "-o output_name" you change the name of the binary, in your case "Sample."

    -W chooses which warnings the compiler should display; in your case, "all" warnings are displayed (it's not "Wall" but "W" and "all" put together ).

    Your output file "Sample" is a binary file, what Windows users would call a .exe. If you must have an extension for your own sake, I think .bin is a popular choice, though you could call it .exe or even .txt and .wtf (the latter two are not encouraged, but you can do it!). Linux itself does not use extensions primarily to determine filetype, though it is often handy for user-sake; I think it is most popular to leave binary files without extensions.

    ***edit
    To name your file with an extension, just add it to your -o arg, e.g.: -o Sample.bin

  3. #3
    Just Joined!
    Join Date
    Aug 2011
    Posts
    38
    That makes sense! The first time I compiled it, I missed the "-o" part and I got an "a" file instead.

    I didn't realise "Wall" was a combination of two things =S

    Thanks, that was really helpful.

  4. $spacer_open
    $spacer_close

Posting Permissions

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