LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-15-2011, 08:54 AM   #1
SharonGe
LQ Newbie
 
Registered: Oct 2010
Distribution: Ubuntu
Posts: 10

Rep: Reputation: 0
I think I dont have a c library in my ubuntu


I wrote a simple program to check if I cam compile c in my ubuntu. and I figure maybe I dont have it. am I right?


user@user-desktop:~/Desktop/s$ more ok.c
#include <stdio.h>
void main()
{
printf("hello world.\n");
exit(0);
}
user@user-desktop:~/Desktop/s$ make ok.c
make: Nothing to be done for `ok.c'.
user@user-desktop:~/Desktop/s$ ./ok
bash: ./ok: No such file or directory
user@user-desktop:~/Desktop/s$ gcc ok.c
ok.c: In function ‘main’:
ok.c:5: warning: incompatible implicit declaration of built-in function ‘exit’
ok.c:3: warning: return type of ‘main’ is not ‘int’
user@user-desktop:~/Desktop/s$ ./ok
bash: ./ok: No such file or directory
 
Old 01-15-2011, 09:00 AM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016 CentOS6.9 CentOS7.3 + 50+ other Linux OS, for test only.
Posts: 16,656

Rep: Reputation: 3281Reputation: 3281Reputation: 3281Reputation: 3281Reputation: 3281Reputation: 3281Reputation: 3281Reputation: 3281Reputation: 3281Reputation: 3281Reputation: 3281
gcc ok.c -o ok

I.e. you have no 'Makefile', then the make command "has nothing to do".

And to get the file 'ok' created, you must specify the file name.

'gcc ok.c' : will create 'a.out' : ./a.out : hello world.

..

Last edited by knudfl; 01-15-2011 at 09:10 AM.
 
Old 01-15-2011, 10:12 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Arch
Posts: 3,136

Rep: Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336Reputation: 1336
GNU make knows how to compile simple C programs without a makefile:

Code:
~/tmp/ok$ cat ok.c
#include <stdio.h>
void main()
{
    printf("hello world.\n");
    exit(0);
}
~/tmp/ok$ make ok
cc     ok.c   -o ok
ok.c: In function ‘main’:
ok.c:5: warning: incompatible implicit declaration of built-in function ‘exit’
~/tmp/ok$ ./ok
hello world.
The argument is the file you want to make, not the file you want to compile.

PS the warning is because you didn't #include stdlib.h which declares the exit function.
 
1 members found this post helpful.
  


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
Trying to use Ubuntu/Ubuntu Studio 10.04 at the Toronto Public Library? MIJ-VI Ubuntu 0 05-20-2010 01:16 PM
Doom 95 on Ubuntu (i dont want prboom) jilloper Linux - Games 8 08-30-2007 04:32 PM
i have a problem in ubuntu but dont know how to fix so please help me gundumfx Linux - Desktop 8 07-23-2007 06:18 PM
ubuntu files (dont know what im doing) boxerboy Linux - Newbie 9 08-17-2005 09:41 AM


All times are GMT -5. The time now is 04:10 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration