Results 1 to 7 of 7
Hi, I am trying to run a very simple program with gcc. THe source code for this program looks like this:
#include <stdio.h>
int main()
{
printf("Hello World");
exit(0);
}
...
- 07-25-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 8
compiling simple programs with gcc
Hi, I am trying to run a very simple program with gcc. THe source code for this program looks like this:
#include <stdio.h>
int main()
{
printf("Hello World");
exit(0);
}
And I saved the program as hello.c.
But when I compile the program using bash, I get the following messages.
charles@linux:~> gcc -o hello hello.c
hello.c: In function ‘main’:
hello.c:6: warning: incompatible implicit declaration of built-in function ‘exit'
Is there something wrong with my source code or am I missing certain key libraries to run this program?
- 07-25-2008 #2
thats a warning, not an error, you should still notice you have the file you intended on building
- 07-25-2008 #3Just Joined!
- Join Date
- Jul 2008
- Posts
- 8
Thanks.
I am not getting any output from the program that I have written. Is there something wrong?
- 07-26-2008 #4Just Joined!
- Join Date
- Jul 2008
- Posts
- 8
Hi I have successfully compiled the program above but i had to include the <stdlib.h> as a header file. However, even if the program compiles I am still not getting any kind of out put.
Someone suggested that I should just type hello at the command prompt. But whenever I do that, I get the following message:
charles@linux:~> hello
bash: hello: command not found
Am I missing something again?
- 07-26-2008 #5
Have you set the permission to execute?
chmod +x hello
You must explicitly tell the OS that a file has permission to execute.
- 07-26-2008 #6Linux User
- Join Date
- Jun 2007
- Posts
- 458
Its not permission that is required. Because your binary file is not in any bin or sbin folder, the folders where the commands are located on UNIX and Linux. For example:
/bin
/usr/bin
/usr/sbin
You need to issue the ./hello command. This will execute the hello file in the directory you are in."When you have nothing to say, say nothing."
- 07-26-2008 #7This will silence the warning.Code:
#include <stdlib.h>


Reply With Quote