'How to run a c program in ubuntu 12.04
Hello i am new to ubuntu. I want to run a c program in ubuntu.On the terminal i typed "make ex1.c" (my file name is ex1) and the after pressing enter button , terminal is telling me that "no rule to make target 'ex1.c'. stop " .
How can i proceed?
Solution 1:[1]
Try this
$ gcc -Wall ex1.c -o ex1
$ ./ex1
-Wall
makes all the warnings explicit. It is considered to be a good practice to always enable -Wall
option. -o ex1
specifies the output executable to be ex1
.
GCC
is the default C compiler on Ubuntu
. An elegant introduction to gcc
can be read in here.
Solution 2:[2]
make
needs no rules to make a simple C file, all it needs is the basename, without the .c
extension:
make ex1
./ex1
I advise you to start using the gcc
command though. You will have more control on how stuff is compiled and along the way, you'll learn how building an application works. make
will start making sense if you have a larger project with many (inter dependent) files.
More (a lot!) information here: http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/, or by typing man gcc
in the terminal.
Solution 3:[3]
Best is to use GCC or you are getting error because you are attaching ".c".So don't put extension in make command.Try without putting extension like following:
make ex1
./ex1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | |
Solution 3 |