DirectXMath.h not self-sufficient on g++ 11.2 (Ubuntu)
denniskb opened this issue · comments
Problem
Trying to compile
#include "DirectXMath.h"
int main() { return 0; }
results in the following error output:
/usr/include/c++/11/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__sample(_InputIterator, _InputIterator, std::input_iterator_tag, _RandomAccessIterator, std::random_access_iterator_tag, _Size, _UniformRandomBitGenerator&&)’:
/usr/include/c++/11/bits/stl_algo.h:5758:28: error: expected ‘,’ before ‘++’ token
5758 | __out[__sample_sz++] = *__first;
| ^~
| ,
/usr/include/c++/11/bits/stl_algo.h:5758:28: error: expected identifier before ‘++’ token
5758 | __out[__sample_sz++] = *__first;
| ^~
/usr/include/c++/11/bits/stl_algo.h: In lambda function:
/usr/include/c++/11/bits/stl_algo.h:5758:32: error: expected ‘{’ before ‘=’ token
5758 | __out[__sample_sz++] = *__first;
| ^
/usr/include/c++/11/bits/stl_algo.h: In lambda function:
/usr/include/c++/11/bits/stl_algo.h:5766:24: error: expected ‘{’ before ‘=’ token
5766 | __out[__k] = *__first;
| ^
/usr/include/c++/11/bits/stl_algo.h: In function ‘_OutputIterator std::__sample(_ForwardIterator, _ForwardIterator, std::forward_iterator_tag, _OutputIterator, _Cat, _Size, _UniformRandomBitGenerator&&)’:
/usr/include/c++/11/bits/stl_algo.h:5809:28: error: expected primary-expression before ‘=’ token
5809 | *__out++ = *__first;
| ^
/usr/include/c++/11/bits/stl_algo.h:5820:28: error: expected primary-expression before ‘=’ token
5820 | *__out++ = *__first;
| ^
/usr/include/c++/11/bits/stl_algo.h:5833:22: error: expected primary-expression before ‘=’ token
5833 | *__out++ = *__first;
| ^
/usr/include/c++/11/bits/stl_algo.h: In function ‘_SampleIterator std::sample(_PopulationIterator, _PopulationIterator, _SampleIterator, _Distance, _UniformRandomBitGenerator&&)’:
/usr/include/c++/11/bits/stl_algo.h:5865:53: error: expected primary-expression before ‘,’ token
5865 | __sample(__first, __last, __pop_cat{}, __out, __samp_cat{}, __d,
|
g++ --version
g++ (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Compile flags: -std=c++20 -O2
Fix
Include <algorithm>
before DirectXMath.h
:
#include <algorithm>
#include "DirectXMath.h"
int main() { return 0; }
compiles fine. I don't know what standard header DirectXMath actually depends on, it just happens to work with <algorithm>
.
The problem is that GNUC's standard C/C++ runtime has some conflicts with Windows SAL annotations required for the library. The workaround for this issue is:
#include <algorithm>
#include <utility>
#include <DirectXMath.h>
This is mentioned in the readme:
https://github.com/microsoft/DirectXMath#compiler-support
Since this does not impact any other toolset (including MinGW on Windows), I do not have these headers included in DirectXMath and I don't actually need them for the library.
Sry completely overlooked that part. Thx for the info!