我需要在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时,定义发生了冲突。
1条答案
按热度按时间piv4azn71#
struct mallinfo
(如果它存在于您的系统中)是在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.