gpt4 book ai didi

c++ - 使用 mingw-w64 时找不到或未正确包含 float.h

转载 作者:太空宇宙 更新时间:2023-11-04 04:28:02 27 4
gpt4 key购买 nike

我正在尝试交叉编译一段使用 float.h 来设置一些 FPU 大小的代码。

需要它的特定代码是:

#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-w64 float.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

最佳答案

好的,经过一番搜索,我在 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. */
/* */

请注意,它说“在 80x86 处理器上”。您正在编译的主机 - Windows 64 位 (x86_64) - 不匹配。

official documentation from Microsoft about the extension 进一步支持了这一点这是您要编译的库使用的:

Mask

_MCW_PC (Precision control)

(Not supported on ARM or x64 platforms.)

[..]

_PC_24 (24 bits)

_PC_53 (53 bits)

_PC_64 (64 bits)

[..]

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

关于c++ - 使用 mingw-w64 时找不到或未正确包含 float.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39514866/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com