2016-09-15 78 views
1

我想,当适当地包括交叉编译一段代码,它使用float.h时设置一些FPU大小。FLOAT.H未找到或使用的MinGW-W64

代码的特定部分,需要它是:

#ifdef SINGLE 
    _control87(_PC_24, _MCW_PC); /* Set FPU control word for single precision. */ 
#else /* not SINGLE */ 
    _control87(_PC_53, _MCW_PC); /* Set FPU control word for double precision. */ 
#endif /* not SINGLE */ 

当我编译,但是,我得到的错误

/home/rcrozier/src/xfemm-hg/mfemm/../cfemm/fmesher/triangle.c:4922:14: error: '_PC_53' undeclared (first use in this function) 
    _control87(_PC_53, _MCW_PC); /* Set FPU control word for double precision. */ 

另一个人解释了什么似乎是更同样的问题细节here。在(较旧的)线程here中描述了一个非常类似的问题。在相关的情况下,我正在使用mingw-w64,但通过M Cross Environment

在这种情况下,float.h问题到底是什么情况,是否有解决方法?

编辑:从gcc的详细输出

Using built-in specs. 
COLLECT_GCC=/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-gcc 
Target: x86_64-w64-mingw32.shared 
Configured with: /opt/mxe/tmp-gcc-x86_64-w64-mingw32.shared/gcc-4.9.4/configure --target=x86_64-w64-mingw32.shared --build=x86_64-unknown-linux-gnu --prefix=/opt/mxe/usr --libdir=/opt/mxe/usr/lib --enable-languages=c,c++,objc,fortran --enable-version-specific-runtime-libs --with-gcc --with-gnu-ld --with-gnu-as --disable-nls --disable-multilib --without-x --disable-win32-registry --enable-threads=win32 --enable-libgomp --with-gmp=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-isl=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-mpc=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-mpfr=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-cloog=/opt/mxe/usr/x86_64-unknown-linux-gnu --with-as=/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-as --with-ld=/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-ld --with-nm=/opt/mxe/usr/bin/x86_64-w64-mingw32.shared-nm 
Thread model: win32 
gcc version 4.9.4 (GCC) 
COLLECT_GCC_OPTIONS='-c' '-I' '../cfemm/fmesher' '-I' '../cfemm/libfemm' '-I' '../cfemm/libfemm/liblua' '-I' '/usr/local/MATLAB/R2015a/extern/include' '-I' '/usr/local/MATLAB/R2015a/simulink/include' '-D' 'MATLAB_MEX_FILE' '-std=c99' '-D' '_GNU_SOURCE' '-fexceptions' '-fPIC' '-fno-omit-frame-pointer' '-pthread' '-v' '-fpermissive' '-D' 'CPU86' '-D' 'MX_COMPAT_32' '-O' '-D' 'NDEBUG' '-o' '/home/rcrozier/src/xfemm-hg/mfemm/../cfemm/fmesher/triangle.o' '-mtune=generic' '-march=x86-64' 
/opt/mxe/usr/libexec/gcc/x86_64-w64-mingw32.shared/4.9.4/cc1 -quiet -v -I ../cfemm/fmesher -I ../cfemm/libfemm -I ../cfemm/libfemm/liblua -I /usr/local/MATLAB/R2015a/extern/include -I /usr/local/MATLAB/R2015a/simulink/include -D_REENTRANT -U_REENTRANT -D MATLAB_MEX_FILE -D _GNU_SOURCE -D CPU86 -D MX_COMPAT_32 -D NDEBUG /home/rcrozier/src/xfemm-hg/mfemm/../cfemm/fmesher/triangle.c -quiet -dumpbase triangle.c -mtune=generic -march=x86-64 -auxbase-strip /home/rcrozier/src/xfemm-hg/mfemm/../cfemm/fmesher/triangle.o -O -std=c99 -version -fexceptions -fPIC -fno-omit-frame-pointer -fpermissive -o /tmp/ccMkwwWD.s 
cc1: warning: command line option '-fpermissive' is valid for C++/ObjC++ but not for C 
GNU C (GCC) version 4.9.4 (x86_64-w64-mingw32.shared) 
    compiled by GNU C version 4.8.4, GMP version 6.1.1, MPFR version 3.1.4, MPC version 1.0.2 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
ignoring nonexistent directory "/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/4.9.4/../../../../x86_64-w64-mingw32.shared/sys-include" 
#include "..." search starts here: 
#include <...> search starts here: 
../cfemm/fmesher 
../cfemm/libfemm 
../cfemm/libfemm/liblua 
/usr/local/MATLAB/R2015a/extern/include 
/usr/local/MATLAB/R2015a/simulink/include 
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/4.9.4/include 
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/4.9.4/include-fixed 
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/4.9.4/../../../../x86_64-w64-mingw32.shared/include 
End of search list. 

编辑:更多信息

我也得到了同样的结果,如果我使用完整的目录路径mingw-w64float.h像这样:

//#include <float.h> 
#include "/opt/mxe/usr/x86_64-w64-mingw32.static/include/float.h" 

编辑更多信息的代码结构

要提供一些进一步的信息,我实际上正在编译C库(头文件和C文件),其中我使用的函数声明包括使用extern C。从头文件中的实际声明如下:

#ifdef __cplusplus 
extern "C" { 
#endif 

#ifdef ANSI_DECLARATORS 
int triangulate(char *, struct triangulateio *, struct triangulateio *, 
       struct triangulateio *, int (*TriMessage)(const char * format, ...)); 
void trifree(VOID *memptr); 
#else /* not ANSI_DECLARATORS */ 
int triangulate(); 
void trifree(); 
#endif /* not ANSI_DECLARATORS */ 

#ifdef __cplusplus 
} 
#endif 

我使用的实际库Triangle。该float.h时包括在triangle.c,看起来像这样:

#ifdef CPU86 
//#include <float.h> 
#include "/opt/mxe/usr/x86_64-w64-mingw32.static/include/float.h" 
#endif /* CPU86 */ 
#ifdef LINUX 
#include <fpu_control.h> 
#endif /* LINUX */ 

你在哪里编译时定义CPU86LINUX。对于交叉构建,我正在定义CPU86

+0

我理解正确吗?你期望float.h来定义_PC_53的东西? **为什么?** –

+0

这是我的谷歌搜索表明,不是吗?你知道真正的问题吗? – crobar

+0

否:http://en.cppreference.com/w/cpp/header/cfloat真正的问题很难说,但可能是一个配置问题。 –

回答

0

OK,经过一番摸索,我发现这个在triangle.c:

/* On some machines, my exact arithmetic routines might be defeated by the */ 
/* use of internal extended precision floating-point registers. The best */ 
/* way to solve this problem is to set the floating-point registers to use */ 
/* single or double precision internally. On 80x86 processors, this may */ 
/* be accomplished by setting the CPU86 symbol for the Microsoft C   */ 
/* compiler, or the LINUX symbol for the gcc compiler running on Linux. */ 
/*                   */ 

注意,它说: “在80×86处理器”。您正在编译的主机 - Windows 64位(x86_64) - 与此不匹配。

这是由的二手由你试图编译库official documentation from Microsoft about the extension进一步支持:

面膜

_MCW_PC(精密控制)

对ARM不支持x64平台。)

[..]

_PC_24(24位)

_PC_53(53比特)

_PC_64(64位)

[..]

因此我猜你需要以不同的方式配置你的版本,可能没有定义CPU86。虽然我不知道这是否真的解决了你的问题,或只是导致错误的结果。毕竟...这个库甚至移植到64位?

+0

你说得很好,但是现在我有机会仔细检查,并且我可以确认使用mingw-w64编译器(特别是TDM-GCC中的版本)可以在Windows上本地编译和运行相同的代码4.9.2)。所以虽然这是值得担心的事情,但我不认为这是问题。我之前确实通过电子邮件发送了有关此作者的原文,但他从未回复。我可以肯定地确认它在64位Linux上编译并解决了许多问题而没有问题。 – crobar

+0

我现在也有机会检查triangle.c,并且在开头的帮助文本中特别提到了64位体系结构(他在推荐使用单精度双精度时提到DEC Alpha),所以我认为原则上'三角形'应该在64位工作,并且实践表明这种情况。 – crobar

+0

嗯...在这些工作版本中,是否有'CPU86'定义?阅读自述文件,我只是将它(以及'LINUX')放在未定义的位置。你可以试试吗? –