Re: no Hello World!!



Thanks for your response.

now my program looks like this...

#include <stdio.h>

int main(void)
{
double number;
printf("\nHello World");
return 0;
}


and I compile it with

gcc -g hello_world.c

now when I run the a.out file I get "Floating point exception" and the
program crashes

gdb a.out

(gdb) run
Starting program: ~/a.out

Program received signal SIGFPE, Arithmetic exception.
0xb7f695d1 in ?? ()

(gdb) bt
#0 0xb7f695d1 in ?? ()
#1 0x00000000 in ?? ()
#2 0x00000000 in ?? ()
........
........
........
#61 0x00000000 in ?? ()
#62 0x08049514 in _DYNAMIC ()
........
........
........
#1429 0x00000000 in ?? ()
Cannot access memory at address 0xbff7e000
(gdb) list
1 in hello_world.c

I have a feeling the problem is in the libraries, but don't know how
to go forward from this point.

-RWit

and ran the a.out file.
On Mar 19, 1:40 pm, j...@xxxxxxxxxxx (Jens Thoms Toerring) wrote:
rwittenb...@xxxxxxxxxxxxxxx wrote:
I wrote a program using the Fedora Core 6 linux enviroment as follows:
#include <stdio.h>
int main()

You better make that

int main( void )

since your main() function doesn't take any arguments.

{
double number;

That line isn't needed at all, 'number' is never used anywhere.

printf("\nHello World");
return 0;
}
I compile this with "gcc -lm hello_world.c"

You should always put the libraries at end of the compile command.
And the program you will get out of this will be called 'a.out'.
If you want a program called 'hello_world' then you would need

gcc -o hello_world hello_world.c -lm

(but since you don't need antyhing from the math library you
can as well drop the '-lm' bit).

On running it on my debian woody system my program crashes with the
message "Floating Point Exception"
(gdb) run
Starting program: ~/hello_world.c

According to the command line above 'hello_world.c' is a C source
file, not a program. I don't really believe that this is the out-
put of gdb if you ask it to "run" a C source file. It will instead
tell you that you didn't specify an executable program

(no debugging symbols found)

No wonder since you didn't tell the compiler to include debugging
symbols into the executable - you would need the additional com-
piler flag '-g' for that.

Program received signal SIGFPE, Arithmetic exception.
0xb7fad5d1 in ?? ()
(gdb) bt
#0 0xb7fad5d1 in ?? ()
#1 0x00000000 in ?? ()
#2 0x00000000 in ?? ()
..............................
..............................
..............................

There are too many things that look as if your don't describe
what you have really done, so I can't come up with any reason-
able explanation. Did you try to run your 'a.out' program?

Regards, Jens
--
\ Jens Thoms Toerring ___ j...@xxxxxxxxxxx
\__________________________ http://toerring.de


.



Relevant Pages

  • Re: Library in library...
    ... > We compile A.cpp and create a library A.lib. ... Yup there is but it depends on the tools you have for creating Libraries. ... int getVal(); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: symbol name corresponding to a address
    ... > addresses for different executables(I discovered it using gdb). ... The libraries are usually loaded into the first ... int main ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.programmer)
  • Re: matlab mex file
    ... indirection from 'int ' ... What libraries or headers do I need to include for this? ... > henry tehrani wrote: ... > You must add several files & libraries to compile list ...
    (comp.soft-sys.matlab)
  • [PATCH 04/37] Separate the gdbstub from the debug core
    ... kernel debugger exception logic and to the gdbstub.c which contains ... the logic for allowing gdb to talk to the debug core. ... -static int write_mem_msg ...
    (Linux-Kernel)
  • Re: GCC difference in size of long int on Suse SLES9 / Suse Professional 10.0
    ... The kernel uses printf() with 'long int', ... I can't compile 'on-the-fly'. ... clashing with the hardware and any libs that you interact with. ... platform types build up their own int types. ...
    (comp.os.linux.development.apps)