5

I get the error

"/usr/include/c++/5/cstddef:51:11: error: ‘::max_align_t’ has not been declared using ::max_align_t; ^"

So I should update the libraries because I find this solution:

"A workaround until libraries get updated is to include <cstddef> or <stddef.h> before any headers from that library."
I wrote some command on the Ubuntu terminal such as:

bash $ sudo apt-get install apt-file
bash $ sudo apt-file update
bash $ apt-file search stddef.h

Then still the error exist. Thank you

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
Learner
  • 89
  • 1
  • 1
  • 5
  • What were you trying to compile? – Christian Rapp Jan 31 '16 at 11:37
  • @Azadeh, you need to give us more information. What are you trying to do? Are you trying to run a program that gives you this error? Or are you getting this error while you try to compile some file of you? – user23573 Jan 31 '16 at 11:41
  • Text must come from https://gcc.gnu.org/gcc-4.9/porting_to.html . Those ubuntu commands are rather useless. – Marc Glisse Jan 31 '16 at 12:05

3 Answers3

7

In the .cpp file where this compile error occurs you need to add

#include <cstddef>

before any of the other headers, e.g.

main.cpp (broken)

#include <cstdio>

int main()
{
    using ::max_align_t;
    puts("Hello World");
    return 0;
}

Try to compile that:

$ g++ -std=c++11 -o test main.cpp
main.cpp: In function ‘int main()’:
main.cpp:5:10: error: ‘::max_align_t’ has not been declared
  using ::max_align_t;
      ^

Then fix it:

main.cpp (fixed)

#include <cstddef>
#include <cstdio>

int main()
{
    using ::max_align_t;
    puts("Hello World");
    return 0;
}

Compile and run it:

$ g++ -std=c++11 -o test main.cpp
$ ./test
Hello World
Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • While `max_align_t` might be in the global namespace on that implementation, it's not guaranteed. Consider correcting your post. – Deduplicator Jan 31 '16 at 12:03
  • @Deduplicator True, but the OP's error is exactly as illustrated and the OP seems to be a) very green, b) not a fluent English speaker. Perhaps best to keep it simple, but feel free to add a refining addendum if you wish. – Mike Kinghan Jan 31 '16 at 12:18
  • Thanks so much Mike Kinghan, Now the newer error "narrowing conversion of long long int to long unsigned int inside {} [-Wnarrowing]! – Learner Feb 01 '16 at 17:21
  • I think error got from [code] const unsigned long int factorial[17] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000};[/code] – Learner Feb 01 '16 at 17:35
  • @Azadeh Welcome to Stackoverflow! If my answer solved the problem you posted, see [how to accept an answer](http://stackoverflow.com/help/accepted-answer). If you now have a new problem, then post a new question. That's how Stackoverflow works. Before you post your new question, see [how to ask a good question](http://stackoverflow.com/help/how-to-ask), so that this time you will not get down-votes. – Mike Kinghan Feb 01 '16 at 17:38
  • accepted it, thank you, I ask the new question on this page:http://stackoverflow.com/questions/35136988/narrowing-conversion-of-long-long-int-to-long-unsigned-int-inside-wnarrowin – Learner Feb 01 '16 at 17:51
0

I compiled some code with GNU C++ 4.9 on CentOS, and the issue was not solved by ensuring top position #include (or by the older header name stddef.h).

Weird enough, I searched all header files of the compiler libraries for the global definition of max_aling_t as declared in the offending using declaration... and found none! Could it be in some 'internal compiled header?

So I simply commented-out the "using ::max_align_t;" line in the standard header (not proud of doing this indeed) and it solved the problem... and code is running...

if anyone can explain what is the meaning/impact of this max_align_t ?

Bernard Hauzeur
  • 2,317
  • 1
  • 18
  • 25
-1

I also commented-out the using ::max_align_t; line in /usr/include/c++/4.9/cstddef, while, code is running, but I don't know if there are any consequences by doing this...

Joel Bodenmann
  • 2,152
  • 2
  • 17
  • 44
  • 2
    You should never ever patch system headers if you "don't know the consequences". My crystal ball says `std::max_align_t` won't compile after this. – HolyBlackCat Jun 19 '20 at 08:46