How to fix “cc1: error: unrecognized command line option ‘-mavx2′”

Question: I am trying to compile a program on CentOS, but it complains "cc1: error: unrecognized command line option '-mavx2'". How can I fix this error?

The error indicates that the GCC compiler you are using does not support "-mavx2" option. This option is supposed to enable the use of AVX2 extended instruction sets in the code that you are compiling the program into. As extensions to the x86 instruction set, AVX/AVX2 is designed to improve the performance and parallelism of floating-point intensive computations.

The "mavx2" option is supported by GCC version 4.7 and higher. Check your GCC version:

$ gcc --version

Most likely the GCC compiler installed on your CentOS is too old to support "mavx2" option.

For example, CentOS 6.X comes with GCC version 4.4.7. If you want to upgrade GCC to versioin 4.7 on CentOS 6.X, you can install devtools. Refer to this guideline to upgrade GCC on CentOS.

Another option is to upgrade to CentOS 7 which comes with GCC 4.8.

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

Leave a comment

Your email address will not be published. Required fields are marked *