未定义参考posix_memalign使用的mingw32 [英] Undefined reference to posix_memalign using mingw32
问题描述
我使用Debian挤压,交叉编译的Windows使用的目标的mingw32。
I'm using Debian Squeeze, cross compiling for windows targets using mingw32.
有关Linux目标,我可以用posix_memalign分配对齐的存储空间。
For a Linux target, I can use posix_memalign to allocate aligned memory.
我似乎无法找到一个方法来得到这个窗户目标工作;我得到未定义的引用错误。我曾尝试几种不同的功能,但没有成功。
I can't seem to find a way to get this to work for windows targets; I get errors about undefined references. I have tried several alternative functions, to no avail.
举例code:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main(void)
{
char *foo;
/* works on linux */
posix_memalign(&foo, 1024, 1024);
/* deprecated linux */
memalign(1024, 1024);
valloc(1024);
/* should work on windows only */
_aligned_malloc(1024, 1024);
}
示例输出,适用于Linux目标(预期):
Example output for a Linux target (expected):
ben@debian6400:~/folder$ gcc --version
gcc (Debian 4.4.5-8) 4.4.5
ben@debian6400:~/folder$ gcc -std=c99 test.c
test.c: In function ‘main’:
test.c:11: warning: implicit declaration of function ‘posix_memalign’
test.c:18: warning: implicit declaration of function ‘_aligned_malloc’
/tmp/ccPwPLsW.o: In function `main':
test.c:(.text+0x55): undefined reference to `_aligned_malloc'
collect2: ld returned 1 exit status
示例输出,适用于Windows目标 - 注意,所有四个功能是不确定的。
Example output for a Windows target -- note that all four functions are undefined
ben@debian6400:~/folder$ i586-mingw32msvc-gcc --version
i586-mingw32msvc-gcc (GCC) 4.4.4
ben@debian6400:~/folder$ i586-mingw32msvc-gcc -std=c99 test.c
test.c: In function ‘main’:
test.c:14: warning: implicit declaration of function ‘posix_memalign’
test.c:17: warning: implicit declaration of function ‘memalign’
test.c:18: warning: implicit declaration of function ‘valloc’
test.c:21: warning: implicit declaration of function ‘_aligned_malloc’
/tmp/ccpH5Dsj.o:test.c:(.text+0x26): undefined reference to `_posix_memalign'
/tmp/ccpH5Dsj.o:test.c:(.text+0x3a): undefined reference to `_memalign'
/tmp/ccpH5Dsj.o:test.c:(.text+0x46): undefined reference to `_valloc'
/tmp/ccpH5Dsj.o:test.c:(.text+0x5a): undefined reference to `__aligned_malloc'
collect2: ld returned 1 exit status
任何想法?
推荐答案
您应该能够使用 _aligned_malloc
。其它功能可缺少的MinGW。
You should be able to use _aligned_malloc
. Other functions can be missing in mingw.
- 更新您的MinGW。它应该在4.6.2工作。
- 尝试
__ mingw_aligned_malloc
代替。 -
包括在此为了您的标题:
- 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
只是一个简单的包装围绕的malloc
/ 免费
。如果一切都失败了,你应该能够把它写自己。
_aligned_malloc
/_aligned_free
is just a simple wrapper around malloc
/free
. If everything else fails, you should be able to write it yourself.
这篇关于未定义参考posix_memalign使用的mingw32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!