Results 1 to 10 of 14
I installed gcc from the apt-get package system and found a website that showed me how to write and run my first c program. The program is just this:
Code:
...
- 08-13-2007 #1Just Joined!
- Join Date
- Oct 2006
- Location
- Denmark, Løgstør
- Posts
- 42
first program in c not working
I installed gcc from the apt-get package system and found a website that showed me how to write and run my first c program. The program is just this:
which I doubt has many errors, but here's my problem. Once I start up a gnome-terminal and writes:Code:#include <stdio.h> main() { printf("Hello, world!\n"); return 0; }
$ gcc hello.c
it prompts this:
gcc is located at /usr/bin/gcc if that is of any help..Code:hello.c:1:19: error: stdio.h: No such file or directory hello.c: In function ‘main’: hello.c:5: warning: incompatible implicit declaration of built-in function ‘printf’
Last edited by devils casper; 08-13-2007 at 01:44 PM. Reason: [code] tags
- 08-13-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Hi,
You have to install libc6-dev.
Regards
- 08-13-2007 #3
Check that you have the libc-dev or libc6-dev package (or something similar) installed.
Stand up and be counted as a Linux user!
- 08-13-2007 #4
Execute this
It will install all necessary packages including libc6-dev and linux-libc-dev.Code:sudo apt-get install build-essential
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 08-13-2007 #5Just Joined!
- Join Date
- Oct 2006
- Location
- Denmark, Løgstør
- Posts
- 42
I installed the libc6-dev, and now it does not prompt an error message when I write "gcc hello.c", now it does nothing, which is, gives no output.
- 08-13-2007 #6Just Joined!
- Join Date
- Oct 2006
- Location
- Denmark, Løgstør
- Posts
- 42
I also installed build-essentials, but the result is still the same. Could there be something wrong with the program?
- 08-13-2007 #7
There should be a file called a.out in the directory where you are compiling your apps. You can run it by doing
If you want your program to have the same name as your file (or any other name for that matter) instead of a.out, you need to doCode:./a.out
Your main function should also have a return type, so your code should be something likeCode:$gcc -o someprog someprog.c
Code:#include <stdio.h> int main(void) { printf("Hello, world!\n"); return 0; }
- 08-13-2007 #8Just Joined!
- Join Date
- Oct 2006
- Location
- Denmark, Løgstør
- Posts
- 42
./a.out prints "hello, world". Will this file always show my output and is it necessary to access the output through it?
- 08-13-2007 #9
Hey,
No need to include <stdio.h> in linux. Your program should be like this.
# cat hello.c
main ()
{
printf("Hello World");
}
# make hello
# cc hello.c -o hello
Or
#./hello.c
Will also throw your output.Regards,
who |grep -i blonde |
date; cd~; unzip; touch;
strip; finger; mount; gasp;
yes; uptime; umount;
sleep

Newbie clicks
http://www.linuxforums.org/forum/lin...ead-first.html
- 08-13-2007 #10
I would not recommend this procedure. ANSI standard C requires includes and return values. You're cutting corners by not returning a status at the end of your program and that's just bad practice.
In my work I've never seen a standard C program that used the above method, so although it may work in theory, I cannot recommend that a new programmer learn a non-standard method that will only lead to confusion later on.Registered Linux user #270181
TechieMoe's Tech Rants


Reply With Quote
