Question about linux compiling with GCC

This is a discussion on Question about linux compiling with GCC within the C++ Programming forums, part of the General Programming Boards category; So, I have researched online, and looked at FAQ's, and nothing is giving me what I need. I am a ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    NE Washinton
    Posts
    38

    Question about linux compiling with GCC

    So, I have researched online, and looked at FAQ's, and nothing is giving me what I need. I am a windows / linux user. On windows, i have a very nifty program called "Bloodshed Dev-C++" which allows me to write the code, compile it, and run it all from one easy to use window. I am trying to move everything to linux, and am a little familiar with the OS, but cannot seem to figure out how to create, and compile, and finally run a C++ / C program. Here is what I thought was the correct way, and dident work.

    pico project.c++

    wrote the basic C++ Hello World program, saved and exited pico.

    gcc project.c++

    (here it made a project.o file, which was what i thought was the executable, but when i do this next step nothing happens.)

    ls /../c

    project.o

    (nothing happens)

    can anyone help me out? Maby a simple step by step set of instructions as how to write/compile/run a C/ C++ program?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The C++ compiler is generally called g++.

    If you don't give a name for the executable (and you didn't), it should have created a file called "a.out"; unless you have an alias made for gcc? Type "alias" and see. I'm not aware of a system where the default is to stop at an object file, unless you give it the -c flag.

  3. #3
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    You have to have gcc installed.

    Remember, file.cpp or file.h are nothing more than "text" files.

    If you're gonna learn linux, you need to learn to compile from the command line.

    Write up a simple "hello world" program and compile it from the command like:
    Code:
    g++ -o program_name source_file.cpp
    After you've familiarized yourself with manually compiling from the command line, learn how to use make.

    BTW: if you really want, you can run Dev C++ just fine under "Wine" for linux. although you'll need wine to run any executables you produce with it.

    All Bloodshed Dev C++ does to compile your projects is use a makefile.
    Last edited by dudeomanodude; 03-07-2008 at 06:40 PM.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  4. #4
    Registered User
    Join Date
    Mar 2008
    Location
    NE Washinton
    Posts
    38
    so, do u use a Text editor to write the program? such as "vi" or "pico" or "joe". for example

    pico project1.c++

    write the hello world, save / exit

    g++ -o project1.c++ project1.cpp

    then what?

  5. #5
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Quote Originally Posted by elsheepo View Post
    so, do u use a Text editor to write the program? such as "vi" or "pico" or "joe". for example
    anything you want
    Quote Originally Posted by elsheepo View Post
    g++ -o project1.c++ project1.cpp
    then what?
    in the same directory run it like this:
    Code:
    ./project1.c++
    though, that's not a very good name for it.

    BTW: I prefer geany, just a fancy text editor really.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  6. #6
    Registered User
    Join Date
    Mar 2008
    Location
    NE Washinton
    Posts
    38
    g++ -o project1.c++ project1.cpp

    when i do that linux tells me

    "
    g++: project1.cpp: No such file or directory
    g++: no input files
    "

  7. #7
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    are you running this command from the same directory you saved project1.cpp in?


    i.e. if you saved project1.cpp to home/yourname/projects/project1/project1.cpp

    you need to open a terminal and "cd ~/projects/project1"

    then re-enter "g++ -o project1 project1.cpp"
    Last edited by dudeomanodude; 03-07-2008 at 06:59 PM.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  8. #8
    Registered User
    Join Date
    Mar 2008
    Location
    NE Washinton
    Posts
    38
    i havent saved any file named "project1.cpp" here is what i have done

    1. > pico project1.c++ (named the file)
    2. > wrote a simple hello world program in C++, saved and exited pico.

    now what?

  9. #9
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Quote Originally Posted by elsheepo View Post
    i havent saved any file named "project1.cpp" here is what i have done

    1. > pico project1.c++ (named the file)
    2. > wrote a simple hello world program in C++, saved and exited pico.

    now what?
    well, where did it save that file?
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  10. #10
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    okay, what linux distro are you using?

    i.e. more inportantly what window manager are you using? (gnome, kde, etc.)
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  11. #11
    Registered User
    Join Date
    Mar 2008
    Location
    NE Washinton
    Posts
    38
    running: Slackware 12.0

    /home/blacksheep/c/project1.c++

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by elsheepo View Post
    g++ -o project1.c++ project1.cpp

    when i do that linux tells me

    "
    g++: project1.cpp: No such file or directory
    g++: no input files
    "
    You've got this backwards, then: the thing following -o is the output file, and the thing all by itself (here project1.cpp) is the source code.

    Note: if you expect anybody to follow along, remember the general rules: C++ source code files have extension "cpp", while (*nix) executables have the extension "" (that is, no extension at all). Therefore: your source code (the stuff you type) should be project1.cpp. You should type
    Code:
    g++ -o project1 project1.cpp
    to turn that source code into the executable file "project1", which you can then run by typing
    Code:
    ./project1
    Edit: I suppose I should mention that the computer isn't going to care. But (above) is what people are going to expect.

  13. #13
    Registered User
    Join Date
    Mar 2008
    Location
    NE Washinton
    Posts
    38
    i just found through my KDE Desktop that it comes with a tool KDevelop it says something about geany when i scroll over it. could this be the tool i need? Alltho i would still love to learn how to do it via command line

  14. #14
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Quote Originally Posted by elsheepo View Post
    running: Slackware 12.0
    yikes, you must be one of those super server buffs.
    Quote Originally Posted by elsheepo View Post
    /home/blacksheep/c/project1.c++
    go there and do what tabstop just told you.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  15. #15
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Quote Originally Posted by elsheepo View Post
    i just found through my KDE Desktop that it comes with a tool KDevelop it says something about geany when i scroll over it. could this be the tool i need? Alltho i would still love to learn how to do it via command line
    well we're trying to get you to compile this from the commmand line.

    using a command-line editor like pico, vi, etc. is something different.

    though I know at least vi has a debug interface built-in... (can't vouge for the others, I just don't know)
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Run time differences in Linux gcc versions
    By circuitbreaker in forum C++ Programming
    Replies: 7
    Last Post: 02-14-2008, 11:09 PM
  2. gcc configuration under linux advice needed
    By vart in forum Tech Board
    Replies: 9
    Last Post: 01-10-2007, 02:46 PM
  3. problems compiling in gcc
    By ra_mer in forum C Programming
    Replies: 6
    Last Post: 09-04-2006, 10:13 PM
  4. Question about Linux Firewall
    By naruto in forum Linux Programming
    Replies: 6
    Last Post: 07-25-2004, 01:39 PM
  5. Question about LINUX
    By River21 in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-17-2001, 07:39 PM

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