f



no Hello World!!

I wrote a program using the Fedora Core 6 linux enviroment as follows:

#include <stdio.h>

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

I compile this with "gcc -lm hello_world.c"

On running it on my debian woody system my program crashes with the
message "Floating Point Exception"

(gdb) run
Starting program: ~/hello_world.c
(no debugging symbols found)

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

When I compile the program in my Red Hat 9.0 box it runs just fine.

I am stumped!!

Can anyone offer me some guidance as to how I can resolve this
problem??

Thanks

RWit

0
rwittenberg
3/19/2007 7:40:56 PM
comp.os.linux.development.apps 5216 articles. 1 followers. Post Follow

15 Replies
237 Views

Similar Articles

[PageSpeed] 48

rwittenberg@pranalytica.com 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  ___      jt@toerring.de
   \__________________________      http://toerring.de
0
jt
3/19/2007 8:40:40 PM
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...@toerring.de (Jens Thoms Toerring) wrote:
> rwittenb...@pranalytica.com 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...@toerring.de
>    \__________________________      http://toerring.de


0
rwittenberg
3/19/2007 9:03:54 PM
rwittenberg@pranalytica.com wrote:
> 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 ?? ()

Wow, that's deep trace, and that without any kind of recursion;-)
Never have ssen anything like that.

Something must be horribly broken with your system. Is that a
run-of-the-mill install or did you something "interesting" like
installing a new libc or mess around with the dynamic loader
(but then you probably wouldn't be able to start any programs
at all)? Does something similar also happen when you compile
other programs?

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

There aren't going to be many libraries needed for this, actually
libc and ld-linux should be all and with them broken probably most
programs wouldn't work anymore. What do you get when you do

ldd a.out

wich tells you which libraries the program is linked against.

                                 Regards, Jens
--
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de
0
jt
3/19/2007 9:46:30 PM
I want to be able to compile with my Fedora Core 6 system and run the
executable on my Debian Woody system. I used to compile on a Red Hat
9.0 box and run on Debian Woody earlier and that worked just fine.
Here is what I see in the 2 scenarios.

Case 1 (compiled on FC6 run on Debian):

On compiling on FC6 and

on FC6

#ldd a.out
        linux-gate.so.1 =>  (0x0057f000)
        libc.so.6 => /lib/libc.so.6 (0x00ad0000)
        /lib/ld-linux.so.2 (0x00ab3000)

After transfering file
on Debian

#ldd a.out
/usr/bin/ldd: line 1:  3164 Floating point
exceptionLD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW=
LD_LIBRARY_VERSION=$verify_out LD_VERBOSE= "$file"

Case 2 (compiled on RH9 and run on Debian):

On compiling on RH9 and

Running on RH9

# ldd a.out
        libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

After transfering file
on Debian

# ldd a.out
        libc.so.6 => /lib/tls/libc.so.6 (0xb7e27000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7f62000)

-RWit

0
rwittenberg
3/19/2007 10:43:48 PM
rwittenberg@pranalytica.com wrote:
>I want to be able to compile with my Fedora Core 6 system and run the
>executable on my Debian Woody system. I used to compile on a Red Hat
>9.0 box and run on Debian Woody earlier and that worked just fine.
>Here is what I see in the 2 scenarios.
>
>Case 1 (compiled on FC6 run on Debian):
>
>On compiling on FC6 and
>
>on FC6
>
>#ldd a.out
>        linux-gate.so.1 =>  (0x0057f000)
>        libc.so.6 => /lib/libc.so.6 (0x00ad0000)
>        /lib/ld-linux.so.2 (0x00ab3000)
>
>After transfering file
>on Debian
>
>#ldd a.out
>/usr/bin/ldd: line 1:  3164 Floating point
>exceptionLD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW=
>LD_LIBRARY_VERSION=$verify_out LD_VERBOSE= "$file"

What happens if you either

   1) remove the useless declaration of a double?

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

Or,

   2) compile it with -lm at the end of the compiler
      command line?

          gcc -g -O2 -W -Wall hello.c -lm

-- 
Floyd L. Davidson            <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@apaflo.com
0
floyd
3/19/2007 11:05:48 PM
On Mar 19, 4:05 pm, f...@apaflo.com (Floyd L. Davidson) wrote:
> rwittenb...@pranalytica.com wrote:
> >I want to be able to compile with my Fedora Core 6 system and run the
> >executable on my Debian Woody system. I used to compile on a Red Hat
> >9.0 box and run on Debian Woody earlier and that worked just fine.
> >Here is what I see in the 2 scenarios.
>
> >Case 1 (compiled on FC6 run on Debian):
>
> >On compiling on FC6 and
>
> >on FC6
>
> >#ldd a.out
> >        linux-gate.so.1 =>  (0x0057f000)
> >        libc.so.6 => /lib/libc.so.6 (0x00ad0000)
> >        /lib/ld-linux.so.2 (0x00ab3000)
>
> >After transfering file
> >on Debian
>
> >#ldd a.out
> >/usr/bin/ldd: line 1:  3164 Floating point
> >exceptionLD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW=
> >LD_LIBRARY_VERSION=$verify_out LD_VERBOSE= "$file"
>
> What happens if you either
>
>    1) remove the useless declaration of a double?
>
>           #include <stdio.h>
>           int main(void) {printf("Hello world!\n"); return 0;}
>
> Or,
>
>    2) compile it with -lm at the end of the compiler
>       command line?
>
>           gcc -g -O2 -W -Wall hello.c -lm
>
> --
> Floyd L. Davidson            <http://www.apaflo.com/floyd_davidson>
> Ukpeagvik (Barrow, Alaska)                         f...@apaflo.com


That does not make any difference.

I removed the double and compiled using "gcc -g -O2 -W -Wall
hello_world.c -lm" and I have tried without the "-lm" and various
combinations of other flags.
When I run on Debian....
# ./a.out
Floating point exception

Running gdb yeilds results very similar to what I have already
described.

Thanks for your suggestion in any case. I am now trying to read up on
what linux-gate.so.1... I wonder if thats causing the problem here.

-RWit

0
rwittenberg
3/19/2007 11:16:18 PM
rwittenberg@pranalytica.com wrote:
> I want to be able to compile with my Fedora Core 6 system and run the
> executable on my Debian Woody system. I used to compile on a Red Hat
> 9.0 box and run on Debian Woody earlier and that worked just fine.
> Here is what I see in the 2 scenarios.

Why didn't you tell from the start that you compiled the program on
one machine and then copied it to another one, trying to run it
there? That normally doesn't work and immediately explains your
troubles.

> Case 1 (compiled on FC6 run on Debian):

> On compiling on FC6 and

> on FC6

> #ldd a.out
>         linux-gate.so.1 =>  (0x0057f000)
>         libc.so.6 => /lib/libc.so.6 (0x00ad0000)
>         /lib/ld-linux.so.2 (0x00ab3000)

> After transfering file
> on Debian

> #ldd a.out
> /usr/bin/ldd: line 1:  3164 Floating point
> exceptionLD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW=
> LD_LIBRARY_VERSION=$verify_out LD_VERBOSE= "$file"

> Case 2 (compiled on RH9 and run on Debian):

> On compiling on RH9 and

> Running on RH9

> # ldd a.out
>         libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
>         /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

> After transfering file
> on Debian

> # ldd a.out
>         libc.so.6 => /lib/tls/libc.so.6 (0xb7e27000)
>         /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7f62000)

Well, obviously FC6 and Woody are different enough systems to
make it impossible to simply copy a program from one machine
to the other and having it run on there, while RH9 and Woody
are similar enough. Probably different versions of the libc or
ld-linux.so, different locations of where the essential libra-
ries are, and maybe different additional libraries required
(as you can see, FC6 needs some linux-gate.so that probably
doesn't even exist on the other systems). Forget about that
and get used to compiling your programs on the target machine,
you're in for a lot of grieve otherwise. Or link statically
if you really have no alternatve to moving the binary, that's
the only more or less practical method.

                             Regards, Jens
--
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de
0
jt
3/19/2007 11:24:18 PM
> Why didn't you tell from the start that you compiled the program on
> one machine and then copied it to another one, trying to run it
> there? That normally doesn't work and immediately explains your
> troubles.

I thought I said that from the first post. Sorry if I wasn't clear
enough. I should have made it more clear.

> Well, obviously FC6 and Woody are different enough systems to
> make it impossible to simply copy a program from one machine
> to the other and having it run on there, while RH9 and Woody
> are similar enough. Probably different versions of the libc or
> ld-linux.so, different locations of where the essential libra-
> ries are, and maybe different additional libraries required
> (as you can see, FC6 needs some linux-gate.so that probably
> doesn't even exist on the other systems). Forget about that
> and get used to compiling your programs on the target machine,
> you're in for a lot of grieve otherwise. Or link statically
> if you really have no alternatve to moving the binary, that's
> the only more or less practical method.

My target machine runs Debian from a compact flash card on a single
board computer. I want to use my "shiny" eclipse environment running
on FC6 to write programs for it. My programs that I ported over from
my old RH9 box into FC6 stopped working on the target system and thats
when I got down to the basics and wrote a hello world program.
The problem is my single board computer is resource constrained and
the debian installed on it is a barebones installation. I do not have
a compiler installed and definitely could not run a software IDE on
it. These are some of the reasons for me having to do it this way.
-RWit

0
rwittenberg
3/19/2007 11:37:41 PM
rwittenberg@pranalytica.com wrote:
> My target machine runs Debian from a compact flash card on a single
> board computer. I want to use my "shiny" eclipse environment running
> on FC6 to write programs for it. My programs that I ported over from
> my old RH9 box into FC6 stopped working on the target system and thats
> when I got down to the basics and wrote a hello world program.
> The problem is my single board computer is resource constrained and
> the debian installed on it is a barebones installation. I do not have
> a compiler installed and definitely could not run a software IDE on
> it. These are some of the reasons for me having to do it this way.

But then you're in for a real lot of work (unless you link
statically, but that that perhaps isn't something you would
like to do when the final excutable is going to run on a
resource-starved system). The libraries you link to (and their
locations) must fit the situation on the target system. You
were lucky that where no essential differences between RH9
and Woody, but you can't expect that to be the case all of
the time.

I wouldn't know how to create an executable on system A that
is then supposed to run on system B - it's not black magic,
some people need to do that all of the time, e.g. to create
programs that then are to be run on an embedded system that
even uses a different processor, but it's going to need a
rather good understanding of how the compiler/linker works
and how to set them up for non-standard work. You probably
will have to install some basic version of a cross-compile
environment - at least you will need all the libraries from
the target system - and you will have to figure out how to
coax gcc to create executables for the other system. I can't
tell but I hope someone else here can give you the necessary
informations. If you're lucky Paul Pluzhnikov will see this
thread - I guess he will be able to tell you how it's to be
done...
                            Regards, Jens
--
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de
0
jt
3/20/2007 12:03:23 AM
On Mar 20, 12:03 am, j...@toerring.de (Jens Thoms Toerring) wrote:
> rwittenb...@pranalytica.com wrote:
> > My target machine runs Debian from a compact flash card on a single
> > board computer. I want to use my "shiny" eclipse environment running
> > on FC6 to write programs for it. My programs that I ported over from
> > my old RH9 box into FC6 stopped working on the target system and thats
> > when I got down to the basics and wrote a hello world program.
> > The problem is my single board computer is resource constrained and
> > the debian installed on it is a barebones installation. I do not have
> > a compiler installed and definitely could not run a software IDE on
> > it. These are some of the reasons for me having to do it this way.
>
> But then you're in for a real lot of work (unless you link
> statically, but that that perhaps isn't something you would
> like to do when the final excutable is going to run on a
> resource-starved system). The libraries you link to (and their
> locations) must fit the situation on the target system. You
> were lucky that where no essential differences between RH9
> and Woody, but you can't expect that to be the case all of
> the time.
>
> I wouldn't know how to create an executable on system A that
> is then supposed to run on system B - it's not black magic,
> some people need to do that all of the time, e.g. to create
> programs that then are to be run on an embedded system that
> even uses a different processor, but it's going to need a
> rather good understanding of how the compiler/linker works
> and how to set them up for non-standard work. You probably
> will have to install some basic version of a cross-compile
> environment - at least you will need all the libraries from
> the target system - and you will have to figure out how to
> coax gcc to create executables for the other system. I can't
> tell but I hope someone else here can give you the necessary
> informations. If you're lucky Paul Pluzhnikov will see this
> thread - I guess he will be able to tell you how it's to be
> done...
>                             Regards, Jens
> --
>   \   Jens Thoms Toerring  ___      j...@toerring.de
>    \__________________________      http://toerring.de

It's not black magic, but cross-compiling is an art.

Basically, you have to devote a directory in which to install
your compiler(s), assembler, linker, and libraries to match
the target. Shell scripts are probably necessary, or at least
carefully thought-out makefiles.

google 'gnu cross-compiling', and check out the gcc lists.

HTH,
  Tarkin

0
Tarkin
3/20/2007 1:32:57 AM
Looks like I need to setup cross compilation and have my task cut out.
Thanks for helping get to the bottom of this. If anyone who sees this
knows of a cool howto online please post the URL.
-RWit

0
rwittenberg
3/20/2007 4:41:27 PM
rwittenberg@pranalytica.com wrote:
> I want to be able to compile with my Fedora Core 6 system and run the
> executable on my Debian Woody system. I used to compile on a Red Hat
> 9.0 box and run on Debian Woody earlier and that worked just fine.
> Here is what I see in the 2 scenarios.
> 
> Case 1 (compiled on FC6 run on Debian):
> 
> On compiling on FC6 and
> 
> on FC6
> 
> #ldd a.out
>         linux-gate.so.1 =>  (0x0057f000)
>         libc.so.6 => /lib/libc.so.6 (0x00ad0000)
>         /lib/ld-linux.so.2 (0x00ab3000)
> 
> After transfering file
> on Debian
> 
> #ldd a.out
> /usr/bin/ldd: line 1:  3164 Floating point
> exceptionLD_TRACE_LOADED_OBJECTS=1 LD_WARN= LD_BIND_NOW=
> LD_LIBRARY_VERSION=$verify_out LD_VERBOSE= "$file"
> 

Does your FC6 have SELinux?

The linux-gate.so.1 library hints toward SELinux.

-- 

Tauno Voipio
tauno voipio (at) iki fi
0
Tauno
3/20/2007 4:49:45 PM
rwittenberg@pranalytica.com wrote:
> Looks like I need to setup cross compilation and have my task cut out.
> Thanks for helping get to the bottom of this. If anyone who sees this
> knows of a cool howto online please post the URL.
> -RWit
> 

Don't know of any howto's. someone else suggested searching for one.
Or try tldp.org.

An alternative would be to install full debian woody (or enough to
compile with anyhow) on another machine or in a separate partition
on your disk. Do most development with shiny baubles, then do final
compile and test on debian with same kernel and libs as target.
0
Joe
3/20/2007 4:56:54 PM
On Mar 20, 4:41 pm, rwittenb...@pranalytica.com wrote:
> Looks like I need to setup cross compilation and have my task cut out.
> Thanks for helping get to the bottom of this. If anyone who sees this
> knows of a cool howto online please post the URL.
> -RWit

http://linux.bytesex.org/cross-compiler.html

5th hit on a (Google) search for 'gcc cross compile'

I don't know how 'cool' it is, but it's a start.

HTH,
  Tarkin


0
Tarkin
3/20/2007 9:51:52 PM
On Mon, 19 Mar 2007 16:16:18 -0700, rwittenberg wrote:

> On Mar 19, 4:05 pm, f...@apaflo.com (Floyd L. Davidson) wrote:
>> rwittenb...@pranalytica.com wrote:
>> >I want to be able to compile with my Fedora Core 6 system and run the
>> >executable on my Debian Woody system.

>> What happens if you either
>>
>>    1) remove the useless declaration of a double?

>>    2) compile it with -lm at the end of the compiler
>>       command line?

> That does not make any difference.

What CPUs are in the two machines?

Is the Woody machine's CPU older than the one in the FC6 machine?

Mike
0
Mike
3/23/2007 12:48:08 AM
Reply: