Find the answer to your Linux question:
Results 1 to 10 of 10
Hello, somebody here knows about gcc? How can I compile this program in CentOS 5.3? #include<cstdlib> #include<iostream> #define pi 3.141592 using namespace std; int main(int argc, char *argv[]) { float ...
  1. #1
    Just Joined!
    Join Date
    Jul 2009
    Posts
    8

    Compiling in CentOS

    Hello, somebody here knows about gcc?

    How can I compile this program in CentOS 5.3?

    #include<cstdlib>
    #include<iostream>
    #define pi 3.141592
    using namespace std;

    int main(int argc, char *argv[])
    {
    float radio, longitud, area;
    cin>> radio;
    longitud = 2*radio*radio;
    area = pi*radio*radio;
    cout<<"radio ="<<radio<<endl;
    cout<<"area ="<<area<<endl;
    cout<<"Presione Enter para continuar"; //system("PAUSE");
    cint.get(); //return EXIT_SUCCESS;
    return 0;
    }

    If you are using DEV C++ you are suppose to use
    system("PAUSE");
    return EXIT_SUCCESS;

    That is why I use cint.get()...

    When I compile I use: gcc filename.cpp
    so I can enter the value

    or gcc -c filename.cpp but nothing happens...

    Do you have any idea, what is wrong or what is the appropriate command to run it? .

    Thank's


    Quote Originally Posted by Cabhan View Post
    Ah, the good ol' days of Dev-C++ .

    Anyway, I personally just use Kate (a KDE Text Editor) and then compile using gcc.

    If you want an IDE, I hear good things about KDevelop, though I always had a few problems with compiling, because it always wanted a Makefile and a configure file.

    Oh well...

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    You're trying to compile C++ code using gcc. That is not going to work. Use g++ instead.
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Blackfooted Penguin daark.child's Avatar
    Join Date
    Apr 2006
    Location
    West Yorks
    Posts
    4,344
    Try something like
    Code:
    g++ -o program program.cpp

  4. #4
    Just Joined!
    Join Date
    Jul 2009
    Posts
    8

    gcc

    Look I tried this:

    g++ program.cpp -o prog

    Then it generates the prog output but the thing is to know how to execute the output?

    I try emacs prog but it does not work since prog must be an .exe or something...

    I try only prog too but it does not work either.

    So how do you execute the output files?


    See ya...
    Quote Originally Posted by daark.child View Post
    Try something like
    Code:
    g++ -o program program.cpp

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Because it puts the executable in the current directory where you compiled it, you probably need to preface the command with a ./ - as in
    Code:
    ./prog
    The current directory is not part of your path by default unless you add it to your PATH environment variable in ~/.bash_profile (assuming you are running the bash shell).
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Just Joined!
    Join Date
    Jul 2009
    Posts
    8

    gcc output

    Hello, yeap the output can not be executed.

    It says bash: file: command not found.

    I did what you suggest ~/.bash_profile and I added

    PATH=usr/bin/ld

    I think this is a file that I have just created by typing ~./bash_profile

    So I guess that I open another file and give some inputs so I can see the output files from gcc...

    Any idea bout it, I will be listening, thank you for your time...




    Quote Originally Posted by Rubberman View Post
    Because it puts the executable in the current directory where you compiled it, you probably need to preface the command with a ./ - as in
    Code:
    ./prog
    The current directory is not part of your path by default unless you add it to your PATH environment variable in ~/.bash_profile (assuming you are running the bash shell).

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by Diving View Post
    Hello, yeap the output can not be executed.

    It says bash: file: command not found.

    I did what you suggest ~/.bash_profile and I added

    PATH=usr/bin/ld

    I think this is a file that I have just created by typing ~./bash_profile

    So I guess that I open another file and give some inputs so I can see the output files from gcc...

    Any idea bout it, I will be listening, thank you for your time...
    Actually, in ~/.bash_profile do this to set your PATH:
    Code:
    export PATH=.:${PATH}
    What you did was to look in the local directory for executables in usr/bin/ld, which likely doesn't exist, so as a result, most everything will not execute on a command line for you.

    Also, for this to take effect, you need to logout of the system and back in again.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #8
    Just Joined!
    Join Date
    Jul 2009
    Posts
    8

    gcc output

    Nop, it still does not work, I restart my lap and nothing happened...

    My file only works when I type:

    ./a.out

    Something wrong is over there, thank you anyway


    Quote Originally Posted by Rubberman View Post
    Actually, in ~/.bash_profile do this to set your PATH:
    Code:
    export PATH=.:${PATH}
    What you did was to look in the local directory for executables in usr/bin/ld, which likely doesn't exist, so as a result, most everything will not execute on a command line for you.

    Also, for this to take effect, you need to logout of the system and back in again.

  9. #9
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    Quote Originally Posted by Diving View Post
    Nop, it still does not work, I restart my lap and nothing happened...

    My file only works when I type:

    ./a.out

    Something wrong is over there, thank you anyway
    Perhaps I'm missing something, but that's correct. If you've successfully compiled and your program executes, what is the problem? The ./ is an absolute path and that's the default behavior for BASH. I guess I'm confused what you're trying to fix?
    Registered Linux user #270181
    TechieMoe's Tech Rants

  10. #10
    Just Joined!
    Join Date
    Jul 2009
    Posts
    8

    gcc output

    Hello, the problem was that originally I could not execute the output file.

    Now I can do with the ./ that I show you before.

    I was looking how to execute the output file from the command line just by typing the file without (./) but nothing yet.

    I am sure it is possiblly. In the same way I am looking how to give colors to the emac files written in verilog. I think I have to modify a couple of files so I can achieve this. If somebody knows about it, I will be around, thank you for your time.

    Mario


    Quote Originally Posted by techieMoe View Post
    Perhaps I'm missing something, but that's correct. If you've successfully compiled and your program executes, what is the problem? The ./ is an absolute path and that's the default behavior for BASH. I guess I'm confused what you're trying to fix?

Posting Permissions

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