You are not logged in.

#1 2011-03-11 16:15:56

armintirand
Member
Registered: 2011-01-30
Posts: 23

gcc not compile hello world in c?

hi
i wrote a hello world example in c language and  i want compile its.object file is created but not created executed file.please write me what command i need and a little hello world in c to test.
thanks

Offline

#2 2011-03-11 16:23:04

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: gcc not compile hello world in c?

Please show us what you have so that we can see if your syntax etc is correct. are you getting and runtime errors - if so, post them.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2011-03-11 16:44:52

armintirand
Member
Registered: 2011-01-30
Posts: 23

Re: gcc not compile hello world in c?

i  write this cod
#include<stdio.h>
int main()
{printf("hello world");
return 0;
}
and my command:
gcc file-name.c
then gcc creat out put file whiteout creating object file and i add executable license to file and run correctly.
but why object file not created??

Offline

#4 2011-03-11 16:51:18

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: gcc not compile hello world in c?

You didn't ask for an object file, you asked for a full compilation. If you want gcc to stop before linking, use the -c option.

Offline

#5 2011-03-11 16:55:51

armintirand
Member
Registered: 2011-01-30
Posts: 23

Re: gcc not compile hello world in c?

and what command for creating executable file from object?

Offline

#6 2011-03-11 17:02:20

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: gcc not compile hello world in c?

You can treat the object file as a source file and just pass it to gcc. It will be recognized as an object file.

Offline

#7 2011-03-11 17:10:42

armintirand
Member
Registered: 2011-01-30
Posts: 23

Re: gcc not compile hello world in c?

for cpp code what command to this works i need?

Offline

#8 2011-03-11 17:12:25

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: gcc not compile hello world in c?

It seems you need to learn more about the basics of C. I would recommend getting a good book and starting from there.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#9 2011-03-11 17:38:07

armintirand
Member
Registered: 2011-01-30
Posts: 23

Re: gcc not compile hello world in c?

no i was programming in windows and good programming but i am a new linux user.and now want to complate migration to linux.thanks for instructions.

Offline

#10 2011-03-11 18:36:04

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: gcc not compile hello world in c?

For C++, use 'g++' instead of gcc

Offline

#11 2011-03-11 21:56:32

radiomist
Member
From: superposicion
Registered: 2009-11-27
Posts: 64

Re: gcc not compile hello world in c?

gcc some.c -o some

Offline

#12 2011-03-12 01:19:17

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: gcc not compile hello world in c?

A good way to do this is build a simple makefile containing just the following 2 lines:

CC=gcc
CFLAGS:=-ggdb -std=c99

The second line is optional and you may have other preferences.  The -ggdb option adds debugging information for the GNU debugger, gdb; and the -std=c99 allows a program that is compliant with the C99 standard to be compiled.  Name this file 'Makefile' and place it in the same directory as your source code file (i.e. hello.c). Then just type

$ make hello

Offline

Board footer

Powered by FluxBB