LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I think I dont have a c library in my ubuntu (https://www.linuxquestions.org/questions/linux-newbie-8/i-think-i-dont-have-a-c-library-in-my-ubuntu-856479/)

SharonGe 01-15-2011 08:54 AM

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

knudfl 01-15-2011 09:00 AM

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.

..

ntubski 01-15-2011 10:12 AM

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.


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