-2

I made a .c file and some random program that popped into my head. Now I'm trying to run it from the terminal. I'm new to ubuntu so it's hard for me to input the commands needed for it's compiling etc. I've saved my file at desktop. I will be grateful if anyone helped me with the full syntax which includes compiling and installing(stuff like I don't know qemu or gcc which I saw on this site) Thank you.

6

If the program is simple just do this:

cd Desktop
gcc program.c -o program
./program

First command puts you to the Desktop where you put the program. The second line compiles the program if it does not use some strange libraries. The third line executes it. Change word program with the name you have given to the file.

0

The gcc compiler comes with all Linux distro's. The syntax is

gcc -o desiredName program.c

And to run the program use

./desiredName

Of Course there are more options you should add. '-Wall' will print out all the warnings and errors when your try to compile it. Be sure to set up a standard as well. The C language used in the kernel is not standards compliant, it is a superset which includes GCC extension, which is why i would recommend gnu99 -std=gnu99. However, the C standard is C99 -std=c99 I also, personally set up an alias, so I don’t have to type this stuff out all the time. I recommend that you do the same.

alias cc="gcc -Wall -std=gnu99 -o "

Now all you have to do is type

cc desiredName program.c
12
  • 2
    Why -std=gnu99? – muru Mar 5 '16 at 16:16
  • For each language compiled by GCC, there is a standard, GCC attempts to follows many versions of that standard, possibly with some exceptions, and possibly with some extensions. gnu99 is the recommended standard. – Andrew Kralovec Mar 6 '16 at 15:49
  • 1
    Recommended by whom? Why not C11? Why recommend using non-standard extensions at all? – muru Mar 6 '16 at 15:51
  • the C language used in the kernel is not standards compliant, it is a superset which includes GCC extension. Hence gnu99. – Andrew Kralovec Mar 6 '16 at 15:52
  • Who said OP is doing kernel programming? They're just starting out. – muru Mar 6 '16 at 15:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.