无法在MacOS上编译调用mallinfo()的C/C++代码

xvw2m8pv  于 11个月前  发布在  Mac
关注(0)|答案(1)|浏览(121)

我需要在MacOS系统上使用C代码中的mallinfo函数的帮助。尽管在我的源文件中包含了<stdlib.h>,但我在使用GNU gcc ver编译代码时遇到了以下错误。12.3.0:

MPI/worker.C: In member function 'int64_t Worker::cmembytes1(uint64_t*)':
MPI/worker.C:181:19: error: aggregate 'Worker::cmembytes1(uint64_t*)::mallinfo minf' has incomplete type and cannot be defined
  181 |   struct mallinfo minf;
      |                   ^~~~
MPI/worker.C:182:19: error: invalid use of incomplete type 'struct Worker::cmembytes1(uint64_t*)::mallinfo'
  182 |   minf = mallinfo() ;
      |                   ^
MPI/worker.C:181:10: note: forward declaration of 'struct Worker::cmembytes1(uint64_t*)::mallinfo'
  181 |   struct mallinfo minf;
      |          ^~~~~~~~
make: *** [<builtin>: MPI/worker.o] Error 1

字符串

**更新:**我怀疑,我的大部分问题来自混合原生macOS头文件和GNU头文件。当我包含用于mallinfo()的macOS SDK时,定义发生了冲突。

piv4azn7

piv4azn71#

struct mallinfo(如果它存在于您的系统中)是在malloc.h中定义的,因此添加:

#include <malloc.h>

字符串
如果它找不到那个头,你就不能使用struct
mallinfo
Gnulib未修复的可移植性问题:
此功能在某些平台上缺失:macOS 11.1,FreeBSD 13.0,NetBSD 9.0,OpenBSD 6.7,Minix 3.1.8,IRIX 6.5,Solaris 11 2010-11,mingw,MSVC 14.

相关问题