Undefined reference to posix_memalign using mingw32

﹥>﹥吖頭↗ 提交于 2019-12-06 11:35:21

You should be able to use _aligned_malloc. Other functions can be missing in mingw.

  • Update your mingw. It should work in 4.6.2.
  • Try __mingw_aligned_malloc instead.
  • Include your headers in this order:

    #include <stdlib.h>
    #include <intrin.h>
    #include <malloc.h>
    #include <windows.h>
    
  • _aligned_malloc/_aligned_free is just a simple wrapper around malloc/free. If everything else fails, you should be able to write it yourself.

The GNU page for Gnulib says this function is missing on mingw platform and they suggest to use Gnulib pagealign_alloc function on these platforms.

(8.632, posix_memalign) This function is missing on some platforms: MacOS X 10.5, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw, MSVC 9, Interix 3.5, BeOS.

and

The Gnulib module pagealign_alloc provides a similar API that returns memory aligned on a system page boundary.

http://www.gnu.org/software/gnulib/manual/html_node/posix_005fmemalign.html

Note that on C11, there is a new function named align_alloc where the alignment can be specified:

#include <stdlib.h>
void *aligned_alloc(size_t alignment, size_t size);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!