2

Possible Duplicate:
Using software floating point on x86 linux

Just for educational reasons I'd like to compile some programmes using the -msoft-float option of gcc, i.e. doing floating point arithmetic without using the x87/sse fpu unit. Take a simple example:

#include <cstdio>
int main(int argc, char** argv) {
   double x=3.14;
   double y=2.71;
   double z=x+y;
   printf("z=%f\n",z);
   return 0;
}

Compile with either (need to disable sse otherwise -msoft-float has no effect)

g++ -msoft-float -mfpmath=387 float.cpp
g++ -msoft-float -m32 float.cpp

and I get

float.cpp:(.text+0x36): undefined reference to `__adddf3'

Now the man page warns me that I might need to provide my own soft-float library. However, since I'm not doing cross-compilation, does this still apply?

   -msoft-float
       Generate output containing library calls for floating point.
       Warning: the requisite libraries are not part of GCC.  Normally the
       facilities of the machine's usual C compiler are used, but this
       can't be done directly in cross-compilation.  You must make your own
       arrangements to provide suitable library functions for cross-
       compilation.

I checked libgcc_s.so as well as other libraries and __adddf3 is indeed nowhere to be found. I also looked into the gcc-4.6.2 source code and there's a directory ./gcc/config/soft-fp/ with all the soft-float routines, but I failed to compile them by hand.

So is there a way to just compile a soft-float library (or do I have to compile a whole new gcc) or have I overseen something more simple?

Community
  • 1
  • 1
user1059432
  • 7,518
  • 3
  • 19
  • 16
  • Great question, but this has been covered before. – Tim Post Nov 22 '11 at 11:13
  • Thanks and sorry for the duplicate. There seems to be a quick solution by manually compiling the contents of `libgcc/soft-fp/` into a library. I've added it to the [other thread](http://stackoverflow.com/questions/1018638/using-software-floating-point-on-x86-linux). – user1059432 Nov 22 '11 at 13:36
  • Thanks :) And no worries, some stuff is just hard to search for. – Tim Post Nov 22 '11 at 13:39

0 Answers0