foonathan / memory

STL compatible C++ memory allocator library using a new RawAllocator concept that is similar to an Allocator but easier to use and write.
https://memory.foonathan.net
zlib License
1.5k stars 195 forks source link

mac build failure - Unable to determine alignment of C++ type long long - no error text #138

Closed ramcharan-palnati closed 2 years ago

ramcharan-palnati commented 2 years ago

Hi,

While building foonathan memory on mac64 with clang++ compiler , I get fatal error from cmake : Could you help me on this. Thanks in advance.

CMake Error at cmake/get_container_node_sizes.cmake:37 (message):
  Unable to determine alignment of C++ type long long - no error text
  matching align_of<..., ##> in compiler output |Change Dir:
  /FastDDS/build/foonathan_memory_vendor/foo_mem-ext-prefix/src/foo_mem-ext-build/src/CMakeFiles/CMakeTmp

  Run Build
  Command(s)://hub/3rdparty/internal/7931347/maci64/gmake/bin/gmake
  cmTC_840cb/fast && gmake[6]: Entering directory
  '/FastDDS/build/foonathan_memory_vendor/foo_mem-ext-prefix/src/foo_mem-ext-build/src/CMakeFiles/CMakeTmp'

   c++
  -DTEST_TYPE="long long" -arch x86_64 -isysroot
  /Applications/Xcode13.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk
  -mmacosx-version-min=10.15 -fPIE -std=gnu++11 -o
  CMakeFiles/cmTC_840cb.dir/get_align_of.cpp.o -c
  FastDDS/build/foonathan_memory_vendor/foo_mem-ext-prefix/src/foo_mem-ext/cmake/get_align_of.cpp

  clang: error: no such file or directory: 'long'

Call Stack (most recent call first):
  cmake/get_container_node_sizes.cmake:55 (get_alignof_type)
  cmake/get_container_node_sizes.cmake:135 (unique_aligned_types)
  src/CMakeLists.txt:80 (get_container_node_sizes)
MiguelCompany commented 2 years ago

@matt-cross You are the one who added the CMake magical generation of node sizes in get_container_node_sizes.cmake. Would you mind taking a look at this?

matt-cross commented 2 years ago

I tried to reproduce this on my Mac and I cannot reproduce the issue. I am using:

From the error it looks like a shell quoting issue. According to CMake docs for add_compile_definition() it should escape the value automatically for the build system; it's not clear to me what could be causing it to fail to escape this in your environment.

I am proposing a workaround that passes in type names without spaces on the compiler command line and then has corresponding using declarations in the source files to convert them back to C++ types.

In testing this, I also found that the std library implementation on MacOS (perhaps just in clang) wraps some container value types in a structure that is not the node type yet has the same size - see https://github.com/llvm/llvm-project/blob/main/libcxx/include/map#L810-L831 . This was causing this code to detect a node type of 0, I added something to handle this issue as well.

foonathan commented 2 years ago

Merged, let me know if that helps.