LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Compiling C with Emacs (http://www.linuxquestions.org/questions/programming-9/compiling-c-with-emacs-166626/)

sdpeelejr 04-05-2004 07:15 PM

Compiling C with Emacs
 
Okay, i'm trying to compile with emacs and here is my code
Code:

#include <stdio.h>
int main()
{
printf("Hello World!\n");
exit(0);
}

I go to Tools > Compile and at the bottom is this
Quote:

Compile: command -k
What I need to know is, what goes after the -k ?

Thanks

:newbie:

tomank 04-05-2004 08:58 PM

i do

gcc {options} sourcefilename.c

sdpeelejr 04-05-2004 09:05 PM

Okay, so I typed

Compile command: make -k gcc {options} hello.c

and it returned
Quote:

make -k gcc {options} hello.c
make: *** No rule to make target `gcc'.
make: *** No rule to make target `{options}'.
make: Nothing to be done for `hello.c'.

Compilation exited abnormally width code 2 at Mon Apr 5 22:02:18
What's wrong?

Sorry for being a newbie:newbie:

Thanks

tomank 04-05-2004 09:21 PM

either use make or gcc not both - i like gcc as a compiler so i use it

assuming your prog is called hello type

gcc hello.c

the {options} bit before is you can add options but if you dont kown what they do just leave them out!

else type

make -k hello.c

if it doesn't work you need to put the dir infront of the name of the file - when you opened emacs and started the buffer you typed C-x C-f to get a new buffer, just put the dir name in, ie

if i had hello.c in my /home/guest dir i would type (for gcc)

gcc /home/guest

i would then get a file called a.out in the same dir as the source file... to run the program just type

./a.out

when you are in the same dir as the file

tomank 04-05-2004 09:22 PM

and just to add - i am a total newbie aswell, i've only had redhat for about 4 days - just stick with it

good luck

sdpeelejr 04-07-2004 08:13 AM

Okay, I typed Compile command: make -k hello.c and it goes
Quote:

cd /home/stevie
make: -k hello.c
make: Nothing to be done for `hello.c'.

Compilation finsished at Wed Apr 7 09:19:13

What am I doing wrong? :confused:

All I need is for this to compile into an executable so I can run the program.

Thanks!

mfeat 04-07-2004 09:22 AM

do make hello without the .c on the end

sdpeelejr 04-07-2004 10:07 AM

Compile command: make -k hello

returned

cd /home/stevie/
make -k hello
cc hello.c -o hello
make: cc: Command not found
make: *** [hello] Error 127

Compilation exited abnormally with code 2 at Wed Apr 7 11:04:50
:cry:

mfeat 04-07-2004 02:34 PM

sounds like you don't have "cc" linked to "gcc", but that's another issue

just put in the following as is (no make -k)

gcc hello.c -o hello

aluser 04-07-2004 10:47 PM

It's really worth learning to write makefiles so that you don't have to retype longer and longer gcc lines as you work on larger projects. here's a little tutorial that babies you through it:

http://www.eng.hawaii.edu/Tutor/Make/

The OP might want to check that he does have gcc installed: I thought it was pretty standard for gcc packages to link cc to gcc for you.


All times are GMT -5. The time now is 06:49 PM.