For class we use VI to write our code on Linux. We then use the built in gcc compiler to compile our code. I just finished my code and it is finally compiling through gcc without any errors but I there is supposed to be output and I cannot see it.
My question is, is there a way to actually run the code on gcc?
And then, what is your choice of compiler for C?
Is there a way to execute code with gcc?
Page 1 of 15 Replies - 223 Views - Last Post: 29 March 2011 - 06:22 PM
Replies To: Is there a way to execute code with gcc?
#2
Re: Is there a way to execute code with gcc?
Posted 29 March 2011 - 02:33 PM
Usually you run the program from the command line where you compiled it. Example: if the program name is myprogram the you would type ./myprogram notice the "./" normally with Linux the current directory is not in the search directory so you need the "./" to indicate that the program is in the current directory.
As for which compiler, for Linux you will usually use gcc for compiling C program. If you want an IDE then I would suggest Code::Blocks.
Jim
As for which compiler, for Linux you will usually use gcc for compiling C program. If you want an IDE then I would suggest Code::Blocks.
Jim
This post has been edited by jimblumberg: 29 March 2011 - 02:35 PM
#3
Re: Is there a way to execute code with gcc?
Posted 29 March 2011 - 02:55 PM
I use... gcc! 
The steps are something like this.
Make a C file, we'll call it foo.c:
Compile it, here with some helpful flags:
Run it:
That's about it.
The steps are something like this.
Make a C file, we'll call it foo.c:
#include <stdio.h>
int main() {
printf("Can you see me now!\n");
return 0;
}
Compile it, here with some helpful flags:
baavgai@DIC:~/Dev/C$ gcc -Wall -o foo foo.c
Run it:
baavgai@DIC:~/Dev/C$ ./foo Can you see me now! baavgai@DIC:~/Dev/C$
That's about it.
#4
Re: Is there a way to execute code with gcc?
Posted 29 March 2011 - 03:27 PM
Hmm, I compiled it fine with just this:
Then when I try to run it with this:
it gives me this error:
Any idea why?
gcc foo.c
Then when I try to run it with this:
./foo.c
it gives me this error:
-bash: ./foo.c: Permission denied
Any idea why?
#5
Re: Is there a way to execute code with gcc?
Posted 29 March 2011 - 03:57 PM
With the commands that you used to compile this program you should have a file named a.out in the directory. If there is a file name a.out you will run your program by typing ./a.out
Edit You may want to check out this link on compiling with gcc.
Jim
Edit You may want to check out this link on compiling with gcc.
Jim
This post has been edited by jimblumberg: 29 March 2011 - 04:17 PM
#6
Re: Is there a way to execute code with gcc?
Posted 29 March 2011 - 06:22 PM
./a.out worked. Thanks for both of yours help.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|