# Intrin\_avx.hpp compile error

**URL:** <https://forum.opencv.org/t/intrin-avx-hpp-compile-error/6677>\
**Category:** C++\
**Tags:** build, core\
**Created:** [December 12, 2021, 12:59pm UTC](https://forum.opencv.org/t/intrin-avx-hpp-compile-error/6677 "2021-12-12T12:59:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhijie\_Zhang](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/zhijie_zhang/32/3995_2.png) [@Zhijie\_Zhang](https://forum.opencv.org/u/Zhijie_Zhang)\
**Post date:** [December 12, 2021, 12:59pm UTC](https://forum.opencv.org/t/intrin-avx-hpp-compile-error/6677/1 "2021-12-12T12:59:11Z")

</div>

Hi, guys, can you give me some advice for the problem.

##### System information (version)

- OpenCV =\> 4.2.0
- Operating System / Platform =\> ubuntu 16.04 64 Bit
- Compiler =\> g++ 7.5.0

##### Detailed description

Compiling the single intrin\_avx.hpp fails when using avx/avx2 supported device.

```auto
[50%] Building CXX object CMakeFiles/test.dir/test.cpp.o
In file included from /home/workspace/Test/test.cpp:2:0:
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:17:1: error: ‘CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN’ does not name a type
 CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN
 ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:24:8: error: ‘__m256’ does not name a type
 inline __m256 _v256_combine(const__m128& lo, const __m128& hi)
        ^ ~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:27:8: error: ‘__m256d’ does not name a type
 inline __m256d _v256_combine(const__m128d& lo, const __m128d& hi)
        ^ ~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:30:35: error: ‘__m256i’ does not name a type
 inline int _v_cvtsi256_si32(const __m256i& a)
                                   ^ ~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp: In function ‘int cv::_v_cvtsi256_si32(const int&)’:
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:31:28: error: ‘_mm256_castsi256_si128’ was not declared in this scope
 { return _mm_cvtsi128_si32(_mm256_castsi256_si128(a)); }
                            ^ ~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:31:28: note: suggested alternative: ‘_v_cvtsi256_si32’
 { return _mm_cvtsi128_si32(_mm256_castsi256_si128(a)); }
                            ^ ~~~~~~~~~~~~~~~~~~~~~
                            _v_cvtsi256_si32
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:31:10: error: ‘_mm_cvtsi128_si32’ was not declared in this scope
 { return _mm_cvtsi128_si32(_mm256_castsi256_si128(a)); }
          ^ ~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:31:10: note: suggested alternative: ‘_v_cvtsi256_si32’
 { return _mm_cvtsi128_si32(_mm256_castsi256_si128(a)); }
          ^ ~~~~~~~~~~~~~~~~
          _v_cvtsi256_si32
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp: At global scope:
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:33:8: error: ‘__m256i’ does not name a type
 inline __m256i _v256_shuffle_odd_64(const__m256i& v)
        ^ ~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:36:8: error: ‘__m256d’ does not name a type
 inline __m256d _v256_shuffle_odd_64(const__m256d& v)
        ^ ~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:40:8: error: ‘__m256i’ does not name a type
 inline __m256i _v256_permute2x128(const__m256i& a, const __m256i& b)
        ^ ~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:44:8: error: ‘__m256’ does not name a type
 inline __m256 _v256_permute2x128(const__m256& a, const __m256& b)
        ^ ~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:48:8: error: ‘__m256d’ does not name a type
 inline __m256d _v256_permute2x128(const__m256d& a, const __m256d& b)
        ^ ~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp: In function ‘_Tpvec cv::v256_permute2x128(const _Tpvec&, const _Tpvec&)’:
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:53:17: error: ‘_v256_permute2x128’ was not declared in this scope
 { return _Tpvec(_v256_permute2x128<imm>(a.val, b.val)); }
                 ^ ~~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:53:17: note: suggested alternative: ‘v256_permute2x128’
 { return _Tpvec(_v256_permute2x128<imm>(a.val, b.val)); }
                 ^ ~~~~~~~~~~~~~~~~~
                 v256_permute2x128
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp: At global scope:
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:56:8: error: ‘__m256i’ does not name a type
 inline __m256i _v256_permute4x64(const__m256i& a)
        ^ ~~~~~~
/usr/local/include/opencv4/opencv2/core/hal/intrin_avx.hpp:60:8: error: ‘__m256d’ does not name a type

```

##### Steps to reproduce

- test.cpp

```auto
#include <stdio.h>
#include "opencv2/core/hal/intrin_avx.hpp"

int main() {
    printf("test\n");
    return 0; 
}

```

- CMakeLists.txt

```auto
CMAKE_MINIMUM_REQUIRED(VERSION 3.15)
PROJECT(test)

SET(CMAKE_CXX_STANDARD 11)

# avx
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")

# opencv
MESSAGE(STATUS "FIND OpenCV on LINUX.")
FIND_PACKAGE(OpenCV REQUIRED)

ADD_EXECUTABLE(test test.cpp)

TARGET_LINK_LIBRARIES(
        test
        ${OpenCV_LIBS}
)

```

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [December 12, 2021, 1:13pm UTC](https://forum.opencv.org/t/intrin-avx-hpp-compile-error/6677/2 "2021-12-12T13:13:32Z")

</div>

> [@Zhijie\_Zhang](#):
>
> OpenCV =\> 4.2.0

please do not bother with such an outdated (prebuilt ?) version  
also, the problem can only be mended by building the opencv libs from src.  
if the problem persists, there’s a CPU\_DISPATCH flag, where you ca remove avx support

---

<div class="post-metadata">

**Author:** ![Zhijie\_Zhang](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/zhijie_zhang/32/3995_2.png) [@Zhijie\_Zhang](https://forum.opencv.org/u/Zhijie_Zhang)\
**Post date:** [December 13, 2021, 9:33am UTC](https://forum.opencv.org/t/intrin-avx-hpp-compile-error/6677/3 "2021-12-13T09:33:41Z")

</div>

Thanks for your advice. [Alexander Alekhin](https://github.com/alalek) told me that the intrin\_avx.hpp could not be directly included. I fix it by including opencv2/core/simd\_intrinsics.hpp and adding -maxv2 compile flag.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [December 13, 2021, 11:22am UTC](https://forum.opencv.org/t/intrin-avx-hpp-compile-error/6677/4 "2021-12-13T11:22:33Z")

</div>

related: [How to fix the compile error when include the opencv intrin\_avx.hpp - Stack Overflow](https://stackoverflow.com/questions/70323813/how-to-fix-the-compile-error-when-include-the-opencv-intrin-avx-hpp)
