Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8023727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:38:44+00:00 2026-06-04T22:38:44+00:00

I’m using Debian Squeeze, cross compiling for windows targets using mingw32. For a Linux

  • 0

I’m using Debian Squeeze, cross compiling for windows targets using mingw32.

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.

Example 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);
}

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

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

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:38:46+00:00Added an answer on June 4, 2026 at 10:38 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.