LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/)
-   -   C programming on Ubuntu (https://www.linuxquestions.org/questions/ubuntu-63/c-programming-on-ubuntu-376731/)

kenneho 10-25-2005 10:11 AM

C programming on Ubuntu
 
Which package do I need to install to get the standard library files for c programming?
Currently, not even
#include <stdio.h>
works. I thought the standard lib files automatically were added when installing the OS, but I guess I was wrong. :)

s_araj 10-25-2005 11:29 AM

Yoou need to install the gcc compiler and the concerned libraries for C programs. You can search for them in the synaptic manager.

kenneho 10-26-2005 03:33 AM

Quote:

Originally posted by s_araj
Yoou need to install the gcc compiler and the concerned libraries for C programs. You can search for them in the synaptic manager.
I've already installed the gcc compiler, but cannot find the concerned libraries. Any ideas?

reddazz 10-26-2005 05:14 AM

When you installed gcc, the standard libraries should have been included as well. What commands are you running when you try to compile the program you have written?

kenneho 10-26-2005 05:25 AM

My test program is as follows:

#include <stdio.h>

int main() {
printf("Hello!");
}


and I compile it with

gcc <filename>

I installed gcc using synaptic, but it seems as the libraries weren't installed by default.

reddazz 10-26-2005 05:37 AM

Try the following
Code:

$gcc -o hello hello.c
then run the program hello by doing
Code:

$./hello

kenneho 10-26-2005 05:55 AM

(I used "gcc <filename>" just as a test. I know that the binary file is then named "a.out")

Okay, I think I fixed it, but I don't know how. :)

I tried "gcc-4.0" instead of just "gcc", and then it compiled. I seems the libraries were installed after all. But what I don't understand
is WHY this worked. "gcc" and "gcc-4.0" is exactly the same, as far as I can tell: running "gcc --version" and "gcc-4.0 --version" displays the
exact same information. Anyways, now even "gcc <filename>" works. :)

I'll try and build a larger project, and see what happens.



Thanks for the help anyways!

scobie 11-06-2005 07:25 AM

hi,

i am also trying to compile a simple helloworld program. i have all the gcc things in the synaptic pakage manager installed. i open a termainal window and went to the directory where the helloworld.c program is. when i use gcc helloworld.c i get the following:
error: stdio.h: No such file or directory. i get the same error when i use $gcc -o helloworld helloworld.c

i am very new to linux and c.

Can anybody help me?

scobie

kenneho 11-06-2005 10:17 AM

Try and execute "gcc-4.0 <source file>", maybe it works.

boxerboy 11-06-2005 10:54 AM

Quote:

Originally posted by reddazz
Try the following
Code:

$gcc -o hello hello.c
then run the program hello by doing
Code:

$./hello

i dont know if it does the same thing but i compile using gcc as (an example of a program named and saved as hello.c) "gcc hello.c -o hello" than run it using "./hello"

reddazz 11-06-2005 11:19 AM

Quote:

Originally posted by boxerboy
i dont know if it does the same thing but i compile using gcc as (an example of a program named and saved as hello.c) "gcc hello.c -o hello" than run it using "./hello"
Its the same thing. :)

boxerboy 11-07-2005 01:16 PM

ty reddazz i wasnt sure if the order things are in mattered i know some or most commands in termianl doesnt really matter.

blankdev 11-07-2005 09:44 PM

sudo apt-get install build-essential

That should get you started.

kenneho 11-08-2005 03:04 AM

Quote:

Originally posted by boxerboy
ty reddazz i wasnt sure if the order things are in mattered i know some or most commands in termianl doesnt really matter.
Command line input are typically implemented as a switch-statement inside a while-loop, so the order of things does not matter.


All times are GMT -5. The time now is 08:08 AM.