public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* newbie gcc question
@ 1999-10-13 15:54 Maggie Owens
  1999-10-13 16:09 ` Matthew Majka
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Maggie Owens @ 1999-10-13 15:54 UTC (permalink / raw)
  To: help-gcc

I have a little experience writing C++ in the dos and windows
environment. Now I am trying to write a c program and compile it in gcc
on a unix system. As a test, I wrote the traditional hello, world
program:
  #include <stdio.h>
  void main()
  {
    printf("Hello, world!");
  }

I compiled it using:
  gcc helloworld.c
Now, I have a.out, which appears to be executable.

I am using the z shell.
I tried typing:
   a.out
and got:
   zsh: command not found: a.out
so I tried
   sh a.out
and got
   a.out: (M-^A)^C^A^K: not found
   a.out: syntax error at line 10: `;;' unexpected
finally, I tried
   ./a.out
and got nothing in response

I feel abysmally stupid. How can I execute my program?
Thanks in advance


--
Autoreplies will (hopefully) bounce. To reply to me, please send mail
to mmowens at panix dot com.


Sent via Deja.com http://www.deja.com/
Before you buy.

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: newbie gcc question...
@ 2002-04-29 20:14 Michael Kahle
  0 siblings, 0 replies; 26+ messages in thread
From: Michael Kahle @ 2002-04-29 20:14 UTC (permalink / raw)
  To: Claudio Bley; +Cc: gcc-help

Claudio,

Thanks for your help!  I just finished downloading the pdf book "Advanced
Linux Programming".  I am going to read some tonight.  Thank you very
much.

Michael

---- "Claudio Bley" <bley@cs.uni-magdeburg.de> wrote:
> >>>>> "Michael" == Michael Kahle <geopoliticus@onebox.com> writes:
> 
>     Michael> I am trying to teach myself the c language and a program
>     Michael> I am creating at compile time is giving me the error:
> 
>     Michael> undefined reference to 'bla_bla1' undefined reference
> to
>     Michael> 'bla_bla2' undefined reference to 'bla_bla3' etc...
> 
>     Michael> This is the first c program I have written that requires
>     Michael> me to use the #include directive in my program.  I have
> a
>     Michael> file called bla_bla.h in this file i have the lines: void
>     Michael> bla_bla1(int); int bla_bla2(int); int bla_bla3(int); I
>     Michael> also have another file called tbla_bla.c that has the
>     Michael> directive: #include "bla_bla.h" in it.  
> 
> Producing an executable program is usually a 2 step process. At first
> you let the compiler generate object files, afterwards the linker
> takes these files and links them together to one executable program.
> 
> So, to generate object files run
> 
> gcc -c <file.c>
> 
> on every C source file you've got.
> 
> Then, run for example:
> 
> gcc foo.o bar.o -lm 
> 
> This will produce the file a.out (use -o <outfile> to name it
> differently) by linking the 2 object files foo.o and bar.o together
> and also linking with the math library when necessary (-lm means to
> search for libm.so or libm.a).
> 
> You should have a look at "Advanced Linux Programming". It gets really
> 'advanced' on some subjects, but it starts out with the basics:
> 
> http://www.advancedlinuxprogramming.com/
> 
> HTH
> Claudio
>  

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Re: newbie gcc question...
@ 2002-04-29 19:51 Michael Kahle
  0 siblings, 0 replies; 26+ messages in thread
From: Michael Kahle @ 2002-04-29 19:51 UTC (permalink / raw)
  To: Andrea 'Fyre Wyzard' Bocci; +Cc: gcc-help

Andrea,

Thank you so much for the wonderful example and more importantly the
explanation!  This silly (now I think so!) problem has been plaguing
me for the past 3 days... don't worry, I took many breaks!

I better understand now what is going on and was able to compile and
run my program!

> In you example, you declared bla_bla1(), bla_bla2(), bla_bla3(), etc...
> but 
> you did not define them.

oops! in my program I actually did have the definition in the header
file, I didn't make that clear in my example to the list.

Thanks again.  This was such a huge help to me...

Happy programming!

Michael 

^ permalink raw reply	[flat|nested] 26+ messages in thread
* newbie gcc question...
@ 2002-04-29 18:21 Michael Kahle
  2002-04-29 18:45 ` Claudio Bley
  2002-04-29 19:48 ` Andrea 'Fyre Wyzard' Bocci
  0 siblings, 2 replies; 26+ messages in thread
From: Michael Kahle @ 2002-04-29 18:21 UTC (permalink / raw)
  To: gcc-help

hello.  I hope this question is not creating any unnecessary noise. 
If it is, i apologize up front and ask you lead me to the correct faq
or other helpful document.

I am trying to teach myself the c language and a program I am creating
at compile time is giving me the error:

undefined reference to 'bla_bla1'
undefined reference to 'bla_bla2'
undefined reference to 'bla_bla3'
etc...

This is the first c program I have written that requires me to use the
#include directive in my program.
I have a file called
bla_bla.h
in this file i have the lines:
void bla_bla1(int);
int bla_bla2(int);
int bla_bla3(int);
I also have another file called
tbla_bla.c
that has the directive:
#include "bla_bla.h"
in it.  When I try and compile this I get the error above. The files
are all located in the same directory and I run gcc from that directory
with the following command line...
gcc -d -l bla_bla.h bla_bla.c -o bla_bla.o

What is causing this error?!  I know I am doing something wrong.  Unfortunatly
the O'Reilly book I am using for my learning (Practical C Programming)
doesn't give a hint as to what command line options I should be using
when using gcc to include header files.  I have poked around on the net
for my answer and tried quite a few different things.

Please help.  I am new to all of this so please be nice. :)

Thank you very much.

Michael 

^ permalink raw reply	[flat|nested] 26+ messages in thread
* Newbie gcc question
@ 1999-09-12 15:32 Wayne Willson
  1999-09-12 15:47 ` Tim Prince
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Wayne Willson @ 1999-09-12 15:32 UTC (permalink / raw)
  To: help-gcc

I'm a sys/network admin trying to learn C (this could be the root of the
problem) with the GNU C compiler.

In a learning C book I just bought it gives this example

--------------------------------------------
#include <stdio.h>

viod main()
{
        printf("Hello Universe");
}



I type "gcc -o hello hello.c"

This is what I get "hello.c: In function `main':
hello.c:6: warning: return type of `main' is not `int'"
------------------------------------------------------

When I try this it works:
#include <stdio.h>

int main()
{
        printf("Hello Universe");
}

------------------------------------------------

This works as well

#include <stdio.h>

main()
{
        printf("Hello Universe");
}

-------------------------------------

Could someone tell me why gcc doesn't work with 'void'  but works with 'int'
and '   ' ?

Thanks






^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2002-04-30  2:51 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-13 15:54 newbie gcc question Maggie Owens
1999-10-13 16:09 ` Matthew Majka
1999-10-14  0:05   ` Johan Nilson
1999-10-14  9:58     ` Matthew Majka
1999-10-31 13:57       ` Matthew Majka
1999-10-31 13:57     ` Johan Nilson
1999-10-31 13:57   ` Matthew Majka
1999-10-13 22:53 ` Konstantinos Adamopoulos
1999-10-31 13:57   ` Konstantinos Adamopoulos
1999-10-14 12:25 ` Maggie Owens
1999-10-31 13:57   ` Maggie Owens
1999-10-31 13:57 ` Maggie Owens
  -- strict thread matches above, loose matches on Subject: below --
2002-04-29 20:14 Michael Kahle
2002-04-29 19:51 Michael Kahle
2002-04-29 18:21 Michael Kahle
2002-04-29 18:45 ` Claudio Bley
2002-04-29 19:48 ` Andrea 'Fyre Wyzard' Bocci
1999-09-12 15:32 Newbie " Wayne Willson
1999-09-12 15:47 ` Tim Prince
1999-09-30 23:56   ` Tim Prince
1999-10-01  0:00   ` Tim Prince
1999-09-12 21:47 ` Chris Gregory
1999-09-30 23:56   ` Chris Gregory
1999-10-01  0:00   ` Chris Gregory
1999-09-30 23:56 ` Wayne Willson
1999-10-01  0:00 ` Wayne Willson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).