Author Topic: common/mptAlloc.cpp:61:20: error: 'aligned_alloc' is not a member of 'std'"  (Read 949 times)

Offline Reino

  • Shy artist
  • Posts: 5
Hello,

I'm cross-compiling (on Windows using Cygwin, MinGW and GCC) libopenmpt for inclusion in FFmpeg. I've updated from 'libopenmpt-0.3.13+release.autotools.tar.gz' to 'libopenmpt-0.4.4+release.autotools.tar.gz' and am now getting the following error:
Code: [Select]
common/mptAlloc.cpp:61:20: error: 'aligned_alloc' is not a member of 'std'
I've done some searching and was able to fix with...
Code: [Select]
export CXXFLAGS="-std=gnu++11"...before running 'configure' and 'make'.
But I was wondering if this is the right approach/fix.

-- Reino

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 237
Just to clarify: you are using MinGW in a Cygwin environment and "cross-compile" to native(/MinGW) Windows?

I have not used cygwin in years, and this particular setup is thus untested for libopenmpt. It should work though.

Which GCC is MinGW using? Which MinGW/msys variant (mingw32 or mingw-w64)?

Anyway, I'll assume MinGW-w64 with what looks like GCC version >= 8.1 for now, which means that configure will enable -std=c++17, which in turn makes mptAlloc.cpp expect working C++17, which GCC/libstdc++ fail to provide on MinGW.
Can you please try the attached patch (and avoid export CXXFLAGS="-std=gnu++11")?

Sorry for the delayed answer. OpenMPT team was busy at Revision demoparty.

Offline Reino

  • Shy artist
  • Posts: 5
Just to clarify: you are using MinGW in a Cygwin environment and "cross-compile" to native(/MinGW) Windows?
[...]
Which GCC is MinGW using? Which MinGW/msys variant (mingw32 or mingw-w64)?
That's exactly right. I'm using this MinGW-w64 build script. Locally I'm already using GCC 8.3.

Can you please try the attached patch (and avoid export CXXFLAGS="-std=gnu++11")?
No errors while compiling libopenmpt. Successfully created a FFmpeg binary with it. Tracker/module files are played/rendered perfectly.
I think it's save to say your patch is a success. Thanks a lot!

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 237
Can you please try the attached patch (and avoid export CXXFLAGS="-std=gnu++11")?
No errors while compiling libopenmpt. Successfully created a FFmpeg binary with it. Tracker/module files are played/rendered perfectly.
I think it's save to say your patch is a success. Thanks a lot!

Great. Fix applied as r11566 (libopenmpt 0.5) and r11567 (libopenmpt 0.4). Will be in the next released update (which will be in a couple of weeks, probably).

Offline Reino

  • Shy artist
  • Posts: 5
Thank you.

Offline Reino

  • Shy artist
  • Posts: 5
While compiling 'libopenmpt-0.4.6+release.autotools.tar.gz' today I got the "aligned_alloc"-error again.
I did some research and found d97665e to be the culprit.
The following change fixed it for me:
Code: [Select]
diff --git a/common/mptAlloc.cpp b/common/mptAlloc.cpp
index abcb83f..002a11a 100644
--- a/common/mptAlloc.cpp
+++ b/common/mptAlloc.cpp
@@ -56,7 +56,7 @@ void* align(std::size_t alignment, std::size_t size, void* &ptr, std::size_t &sp
 
 aligned_raw_memory aligned_alloc_impl(std::size_t size, std::size_t count, std::size_t alignment)
 {
- #if MPT_CXX_AT_LEAST(17) && !defined(MPT_COMPILER_QUIRK_NO_ALIGNEDALLOC)
+ #if MPT_CXX_AT_LEAST(17) && defined(MPT_COMPILER_QUIRK_NO_ALIGNEDALLOC)
  std::size_t space = count * size;
  void* mem = std::aligned_alloc(alignment, space);
  if(!mem)
@@ -103,7 +103,7 @@ aligned_raw_memory aligned_alloc_impl(std::size_t size, std::size_t count, std::
 
 void aligned_free(aligned_raw_memory raw)
 {
- #if MPT_CXX_AT_LEAST(17) && !defined(MPT_COMPILER_QUIRK_NO_ALIGNEDALLOC)
+ #if MPT_CXX_AT_LEAST(17) && defined(MPT_COMPILER_QUIRK_NO_ALIGNEDALLOC)
  std::free(raw.mem);
  #elif MPT_COMPILER_MSVC || (defined(__clang__) && defined(_MSC_VER))
  _aligned_free(raw.mem);

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 237
This not the correct fix. The correct fix would be to ensure that MPT_COMPILER_QUIRK_NO_ALIGNEDALLOC gets defined on that particular platform, which in fact got broken by the referenced commit.
The breakage happens because we need to determine the C++ standard library that is used (macro __GLIBCXX__) which however is impossible to do before we include any C++ standard library header. We cannot include such headers in CompilerDetect.h because library configuration macros are established only after including CompilerDetect.h in BuildSettings.h.
I'll probably have move the definition of MPT_COMPILER_QUIRK_NO_ALIGNEDALLOC  into BuildSettings.h.

Offline manx

  • OpenMPT Developers
  • *****
  • Posts: 237
While compiling 'libopenmpt-0.4.6+release.autotools.tar.gz' today I got the "aligned_alloc"-error again.

Can you please try applying both attached patches instead of your patch? I'm reasonably sure that they should fix the issue, however I currently have no system to test this myself.

Offline Reino

  • Shy artist
  • Posts: 5
I wasn't notified (e-mail) by your post, but in the meantime I did notice your Fix detection of libstdc++ for MPT_COMPILER_QUIRK_NO_ALIGNEDALL commit, which I turned into a diff suitable for 'libopenmpt-0.4.6+release.autotools.tar.gz'.

'libopenmpt_fix-detection-of-libstdc++.diff':
Code: [Select]
diff -ur common/BuildSettings.h.bak common/BuildSettings.h
--- common/BuildSettings.h.bak 2018-09-15 15:07:34.000000000 +0200
+++ common/BuildSettings.h 2019-08-24 20:33:13.718750000 +0200
@@ -731,6 +731,20 @@
 
 
 
+// standard library quirks
+
+#if MPT_CXX_AT_LEAST(17)
+#if (MPT_COMPILER_GCC || MPT_COMPILER_CLANG)
+// we need to detect the standard library via macro __GLIBCXX__
+#include <vector>
+#endif
+#if MPT_COMPILER_MSVC || MPT_GCC_BEFORE(8,1,0) || MPT_CLANG_BEFORE(5,0,0) || (MPT_COMPILER_GCC && defined(__GLIBCXX__) && (defined(__MINGW32__) || defined(__MINGW64__))) || (MPT_COMPILER_CLANG && defined(__GLIBCXX__)) || (MPT_COMPILER_CLANG && MPT_OS_MACOSX_OR_IOS) || MPT_OS_OPENBSD || MPT_OS_EMSCRIPTEN || (defined(__clang__) && defined(_MSC_VER))
+#define MPT_COMPILER_QUIRK_NO_ALIGNEDALLOC
+#endif
+#endif
+
+
+
 // third-party library configuration
 
 #if defined(MODPLUG_TRACKER)
diff -ur common/CompilerDetect.h.bak common/CompilerDetect.h
--- common/CompilerDetect.h.bak 2019-07-26 12:11:44.000000000 +0200
+++ common/CompilerDetect.h 2019-08-24 20:27:59.937500000 +0200
@@ -311,9 +311,3 @@
 #define MPT_COMPILER_QUIRK_MSVC_STRINGSTREAM
 #endif
 
-#if MPT_CXX_AT_LEAST(17)
-#if MPT_COMPILER_MSVC || MPT_GCC_BEFORE(8,1,0) || MPT_CLANG_BEFORE(5,0,0) || (MPT_COMPILER_GCC && defined(__GLIBCXX__) && (defined(__MINGW32__) || defined(__MINGW64__))) || (MPT_COMPILER_CLANG && defined(__GLIBCXX__)) || (MPT_COMPILER_CLANG && MPT_OS_MACOSX_OR_IOS) || MPT_OS_OPENBSD || MPT_OS_EMSCRIPTEN || (defined(__clang__) && defined(_MSC_VER))
-#define MPT_COMPILER_QUIRK_NO_ALIGNEDALLOC
-#endif
-#endif
-

And this proved successful. Thanks.