7

I'm trying to test some of the functions in fenv.h, however, when I compile the below function ld fails with undefined reference to 'feclearexcept' and undefined reference to 'fetestexcept'. I'm running hardened gentoo compiled against uclibc, and I suspect that this is at least somewhat related

#include <stdio.h>      /* printf */
#include <math.h>       /* sqrt */
#include <fenv.h>      
#pragma STDC FENV_ACCESS on

int main ()
{
  feclearexcept (FE_ALL_EXCEPT);
  sqrt(-1);
  if (fetestexcept(FE_INVALID)) printf ("sqrt(-1) raises FE_INVALID\n");
  return 0;
}

fenv.h is in /usr/include. There are static and dynamic libraries (libm.a, libm.so) in /usr/lib. I am compiling with gcc -o test test.c -lm; does anyone have any ideas why the linker can't find the relevant functions. It seems like nothing in fenv.h has a corresponding library.

UPDATE: this decade old blog post seems to suggest that fenv is not supported by uclibc. I cannot determine if this is the case still, but if it were is there anything to be done. http://uclibc.10924.n7.nabble.com/missing-fenv-h-for-qemu-td2703.html

4

2 回答 2

7

库最后,尝试编译

$ gcc -o test test.c -lm

我使用上面的编译语句在我的 x86_64 Linux 系统上尝试了你的确切程序,它构建并运行得很好:

$ gcc -o fenv fenv.c -lm
$ ./fenv
sqrt(-1) raises FE_INVALID

我生成的二进制文件具有以下依赖项:

$ ldd ./fenv
    linux-vdso.so.1 =>  (0x00007ffd924b7000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fca457e8000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fca4541e000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fca45af0000)

我还验证了这些函数fenv.h确实存在于数学库中:

emil@synapse:~/data/src$ strings /lib/x86_64-linux-gnu/libm.so.6 | grep -E ^fe
feclearexcept
fegetexceptflag
feraiseexcept
fesetexceptflag
fetestexcept
fegetround
fesetround
fegetenv
feholdexcept
fesetenv
feupdateenv
fedisableexcept
feenableexcept
fegetexcept

因此,您的设置中可能还有其他问题。

于 2015-10-17T21:05:39.730 回答
0

最近的 uclib-ng 记录了缺乏对fenv.hat 的支持:https ://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/docs/uClibc_vs_SuSv3.txt?h=v1.0.29#n104

Unimplemented mathematical interfaces:
--------------------------------------
math.h: [126] many
complex.h: [46] all, except cabs
fenv.h: [11] all
于 2018-03-31T10:15:39.327 回答