View Full Version : Where are the C libraries?
bb2120
June 22nd, 2006, 08:42 PM
First of all, hi everyone.
After managing to install Ubuntu (which was a lot easier than I expected), I am now having trouble compiling hello.c into a binary. Oh dear.
The first hurdle was realising I needed to sudo apt-get install gcc
However, now when I try cc hello.c I get the following message in the terminal:
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’
I presume that this is due to the lack of the stdio.h library.
Could someone please explain to me what I need to do to be able to compile c programs. I have a solid knowledge of programming (mainly php), but don't expect me to know my way around Ubuntu.
P.S. I'm running Breezy Badger
glinsvad
June 22nd, 2006, 09:16 PM
sudo apt-get install build-essential
It includes libc-dev, gcc, g++, make and dpkg-dev which should suffice for C/C++ programming. For downloadable documentation also check out glibc-doc and libstdc++6-4.0-doc...
bb2120
June 22nd, 2006, 09:23 PM
Thaks for the quick reply but there are more problems...
bede@bedepc:~$ sudo apt-get install build-essential
Password:
E: Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
What do I do now? I presume I'm having problems because I did sudo apt-get install gcc which installed half of the stuff that build-essential does.
Is there any way to completely undo sudo apt-get install gcc so that I can sudo apt-get install build-essential without problems? Or is that not worth doing?
glinsvad
June 22nd, 2006, 09:42 PM
Usually I only get those kinds of install-errors when I'm running Synaptics while using apt-get... just kill Synaptics and rerun the command
bb2120
June 22nd, 2006, 09:50 PM
Problem solved. Glinsvad, I love you (Don't get any ideas, though)
Monika
June 23rd, 2006, 03:18 PM
I have the same problem, but build-essential hasn't solved it :( Any ideas what other packages I might be missing?
glinsvad
June 23rd, 2006, 03:57 PM
I have the same problem, but build-essential hasn't solved it :( Any ideas what other packages I might be missing?
Could you describe the problem? Is it when running gcc/g++ or installing through apt-get? What error messages do you see?
glinsvad
June 23rd, 2006, 04:13 PM
For easy reference I'm giving the Hello-example
Create a file called hello.cpp with the following code:
#include <iostream>
using namespace std;
int main(int nArgs, char **szArgs)
{
cout<<"Hello" <<endl;
}
Now to compile it, run this command:
g++ hello.cpp -o hello
Finally run the program
./hello
Monika
June 23rd, 2006, 06:14 PM
I'm still getting the same compilation errors that bb2120 had before the install:
hello.c:1:20: error: studio.h: No such file or directory
hello.c: In function ‘main’:
hello.c:4: warning: incompatible implicit declaration of built-in function ‘printf’
The install has improved the situation cause I remember having these same problems compiling programs in C++ before (haven't tried for a while) and now it *does* work :D But I still don't have the libraries for C apparently.
In case you want to check if it's not a mistake on my end (I am a beginner), the program looks like this:
#include <studio.h>
int main() {
printf("Hello");
return 0;
}
And I'm trying to compile it like this:
gcc hello.c -o hello
Thanks for your help :)
hod139
June 23rd, 2006, 06:27 PM
It's
<stdio.h>
not
<studio.h>
(no u)
bb2120
June 23rd, 2006, 06:36 PM
It's an easy mistake to make. It's an abbreviation of Standard I/O
Monika
June 23rd, 2006, 07:47 PM
](*,)
Thanks for pointing that out! :)
Jessehk
June 23rd, 2006, 07:57 PM
#include <iostream>
using namespace std;
int main(int nArgs, char **szArgs)
{
cout<<"Hello" <<endl;
}
That is not really good C++.
This is an ideal "Hello, world" program:
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
}
and in C:
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}
:)
glinsvad
June 23rd, 2006, 08:07 PM
That is not really good C++.
Eeeh, our two examples in C++ do exactly the same thing. If the program only uses the standard (std) namespace, then what's the problem? I recent having to do ten extra keypresses (two times "std::") every time I print something to the screen. Besides, it was taken directly out of an official C++ textbook...
mepapp
June 25th, 2006, 02:20 PM
hello. I just installed build-essential and compiled a "hello world" successfully. However, upon compiling a more complex program, gcc failed to find either stdio.h or math.h. As background: I had the exact same problem before, with Breezy: it worked for a little while and suddenly the files just disappeared. I updated to Dapper thinking it would fix the problem. Again, brief success followed by failure. I have tried reinstalling libc6 but that hasn't helped.
My program(from a c tutorial):
#include < stdio.h>
#include < math.h>
int main()
{
int angle_degree;
double angle_radian, pi, value;
printf ("\nCompute a table of the sine function\n\n");
pi = 4.0*atan(1.0);
printf ( " Value of PI = %f \n\n", pi );
printf ( " angle Sine \n" );
angle_degree=0;
while ( angle_degree <= 360 )
{
angle_radian = pi * angle_degree/180.0;
value = sin(angle_radian);
printf ( " %d %f \n ", angle_degree, value );
angle_degree = angle_degree + 10;
}
return 0;
}
My (repeated) error message:
$ gcc hello.c -lm
hello.c:1:20: error: stdio.h: No such file or directory
hello.c:2:19: error: math.h: No such file or directory
hello.c: In function ‘main’:
hello.c:8: warning: incompatible implicit declaration of built-in function ‘printf’
hello.c:12: warning: incompatible implicit declaration of built-in function ‘atan’
hello.c:22: warning: incompatible implicit declaration of built-in function ‘sin’
mepapp
June 25th, 2006, 02:26 PM
Incidentally, this doesn't work (now) either:
#include < stdio.h>
int main()
{
printf("Hello World!");
return 0;
}
because
~$ gcc hello.c
hello.c:1:20: 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’
mepapp
June 25th, 2006, 02:58 PM
Apparently libc6-dev is the package I'm looking for, but rebuilding that makes no difference.
mepapp
June 25th, 2006, 03:44 PM
Someone take me out the backdoor and put me out of my misery....
The ()/$%&§$§/!!! spaces in this (http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/c_tutorial.html) tutorial led me to reinstall my girlfriend's whole system, and delete many files when space became a premium etc. etc. etc.
Trust the packages first, your own code second.
thanks lamego (on irc), whoever you are
glinsvad
June 25th, 2006, 08:10 PM
True, the tutorial is pretty lame. Just to pencil it out so everybody will know what went wrong:
It is:
#include <stdio.h>
Not:
#include < stdio.h>
No space in front of stdio.h! The compiler is told to look for a file called " stdio.h" but the correct library is in "stdio.h"...
EDIT: Same problem with #include < math.h>
Powered by vBulletin® Version 4.2.2 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.