- edited description
Compiling on Windows/minGW
Hello to everyone, I was trying to compile the last source code for the Blaze-lib with the MinGW (TDM) with GCC version 5.1.0 and I found a problem concerning the definition of the aligned allocation in the "Memory.h" header, precisely the functions allocate_backend and deallocate_backend.
Here the code correctly takes into account the Microsoft Compiler calling for _aligned_malloc functions but it fails whenever MinGW is used because it looks for the posix_memalign function.
Following https://sourceforge.net/p/mingw-w64/discussion/723798/thread/ca63be68/ I modified the source as follows:
Up in the header:
#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW32__)
# include <malloc.h>
#endif
for allocate_backend:
#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR)
raw = _aligned_malloc( size, alignment );
if( raw == nullptr ) {
#elif defined(__MINGW32__)
raw = __mingw_aligned_malloc( size, alignment );
if( raw == nullptr ) {
#else
if( posix_memalign( &raw, alignment, size ) ) {
#endif
for deallocate_backend
#if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR)
_aligned_free( const_cast<void*>( address ) );
#elif defined(__MINGW32__)
__mingw_aligned_free( const_cast<void*>( address ) );
#else
free( const_cast<void*>( address ) );
#endif
According to https://sourceforge.net/p/mingw-w64/wiki2/Missing%20_aligned_malloc/ we should use other headers with specific order. However, by only making the modifications above my code is correctly compiling. I also found in https://stackoverflow.com/questions/16376942/best-cross-platform-method-to-get-aligned-memory that this piece of code is identical to some older version of Eigen. In the latest version the alligned memory allocation is managed with a custom code (https://github.com/RLovelett/eigen/blob/master/Eigen/src/Core/util/Memory.h).
I'm not an expert so I'm not sure what's the best solotion.
Comments (5)
-
reporter -
Hi Daniele!
Thank you very much for your proposal. This is indeed very helpful for us since MinGW is not part of our usual test suite. We also highly appreciate the proposed working solution. Thanks a lot! We will take care of this issue as soon as possible.
Best regards,
Klaus!
-
-
assigned issue to
-
assigned issue to
-
- changed status to open
-
- changed status to resolved
The extension of the
allocate_backend()
anddeallocate_backend()
functions for MinGW has been implemented as proposed. It is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.2. - Log in to comment