I was trying to compile a minimal example of a C++ program using a function from the standard library, that is available only in C++11 and newer, namely std::log2 from the cmath header. However, I am getting an error ‘log2’ is not a member of ‘std’; did you mean ‘log’? when compiling.
Question: Why is std::log2 not available after #include <cmath>? Am I missing something (build options, …)?
Some related info:
project for reference: testCppStd.zip (37.0 KB) (AS6.3, AR 6.4.2)
program appears to be compiled with C++ >= 11, at least static_assert(__cplusplus >= 201103L, “This code requires C++11 or later”); does not cause a compile error
adding -std=c++11 to the additional build options did not change the situation
here is the source of the minimal C++ example:
#include <bur/plctypes.h>
#ifdef _DEFAULT_INCLUDES
#include <AsDefault.h>
#endif
static_assert(__cplusplus >= 201103L, "This code requires C++11 or later");
#include <cmath>
// amount of memory to be allocated for heap storage must be specified for every ANSI C++ program with the bur_heap_size variable
unsigned long bur_heap_size = 0xFFFF;
void _CYCLIC ProgramCyclic(void)
{
double a = std::log2(4.0);
a = a + a; // silence "unused variable"
}
Thanks Christoph, this is a workaround for the specific case, sure.
However, log2 was merely chosen as a more or less arbitrary example for any “new” function in std from <cmath>. Others, like std::trunc etc. show the same behavior. So code relying on a recent std-lib will fail, that is my point.
To check if this is a more general behavior, I tried to use std::unordered_map from the <unordered_map> header which compiled without problems. So there are C++11 std-lib features that work as expected.
QCAS-4148: CASE-59277 - using std namespace in C++ returns error during compilation - Status: Corrective action(s) scheduled
This problem will be solved with a new GCC version planned for AS 6.9.