LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices

Reply
 
Search this Thread
Old 10-25-2005, 10:11 AM   #1
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Rep: Reputation: 40
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.
 
Old 10-25-2005, 11:29 AM   #2
s_araj
Member
 
Registered: Feb 2005
Location: Mumbai, India
Distribution: FC 2 | Ubuntu 5.04 | SuSE 9.3
Posts: 46

Rep: Reputation: 15
Yoou need to install the gcc compiler and the concerned libraries for C programs. You can search for them in the synaptic manager.
 
Old 10-26-2005, 03:33 AM   #3
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
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?
 
Old 10-26-2005, 05:14 AM   #4
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 73
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?
 
Old 10-26-2005, 05:25 AM   #5
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
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.
 
Old 10-26-2005, 05:37 AM   #6
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 73
Try the following
Code:
$gcc -o hello hello.c
then run the program hello by doing
Code:
$./hello

Last edited by reddazz; 10-26-2005 at 02:18 PM.
 
Old 10-26-2005, 05:55 AM   #7
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
(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!
 
Old 11-06-2005, 07:25 AM   #8
scobie
LQ Newbie
 
Registered: Nov 2005
Posts: 1

Rep: Reputation: 0
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
 
Old 11-06-2005, 10:17 AM   #9
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
Try and execute "gcc-4.0 <source file>", maybe it works.

Last edited by kenneho; 11-06-2005 at 10:19 AM.
 
Old 11-06-2005, 10:54 AM   #10
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Rep: Reputation: 32
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"
 
Old 11-06-2005, 11:19 AM   #11
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 73
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.
 
Old 11-07-2005, 01:16 PM   #12
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Rep: Reputation: 32
ty reddazz i wasnt sure if the order things are in mattered i know some or most commands in termianl doesnt really matter.
 
Old 11-07-2005, 09:44 PM   #13
blankdev
LQ Newbie
 
Registered: Nov 2005
Location: Diamond Bar, California
Distribution: Ubuntu
Posts: 11

Rep: Reputation: 0
sudo apt-get install build-essential

That should get you started.

Last edited by blankdev; 11-08-2005 at 08:33 PM.
 
Old 11-08-2005, 03:04 AM   #14
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
which programming language is used to do tcp/ip programming?? gajaykrishnan Linux - Networking 9 12-21-2012 05:16 AM
Ubuntu / Ubuntu + KDE / Kubuntu | Which do you use? BuckRogers01 Ubuntu 60 07-08-2006 12:24 AM
XP doesn't recognize Ubuntu, Ubuntu installed first. MonkeyBusiness Linux - Newbie 9 06-21-2006 03:58 AM
Difference between Top Down programming & Bottom up programming minil Programming 1 06-17-2005 02:42 AM
Clean install from Ubuntu Warty to Ubuntu Hoary Erik_the_Red Linux - Newbie 2 06-05-2005 07:14 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration