# Regarding setting flags while building opencv c++

**URL:** <https://forum.opencv.org/t/regarding-setting-flags-while-building-opencv-c/13333>\
**Category:** Uncategorized\
**Tags:** build, cmake\
**Created:** [May 28, 2023, 5:32am UTC](https://forum.opencv.org/t/regarding-setting-flags-while-building-opencv-c/13333 "2023-05-28T05:32:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![opencvnoob](https://avatars.discourse-cdn.com/v4/letter/o/c0e974/32.png) [@opencvnoob](https://forum.opencv.org/u/opencvnoob)\
**Post date:** [May 28, 2023, 5:32am UTC](https://forum.opencv.org/t/regarding-setting-flags-while-building-opencv-c/13333/1 "2023-05-28T05:32:50Z")

</div>

So whenever we build opencv from source we end up setting the flag  
OPENCV\_ENABLE\_NONFREE=ON.  
Not doing this results in the dreaded error “xfeatures2d.hpp not found” or something similar to that.  
So my question how does setting this particular flag.I mean once this flag is set the cmake build works fine and you end up with the perfect opencv build.  
It’s just a random thought that popped in my mind at 1AM .

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [May 28, 2023, 12:58pm UTC](https://forum.opencv.org/t/regarding-setting-flags-while-building-opencv-c/13333/2 "2023-05-28T12:58:39Z")

</div>

Platform?  
how do you download opencv and opencv\_contrib?  
What is you cmake command?  
Can you give full error message?

---

<div class="post-metadata">

**Author:** ![opencvnoob](https://avatars.discourse-cdn.com/v4/letter/o/c0e974/32.png) [@opencvnoob](https://forum.opencv.org/u/opencvnoob)\
**Post date:** [May 28, 2023, 4:49pm UTC](https://forum.opencv.org/t/regarding-setting-flags-while-building-opencv-c/13333/3 "2023-05-28T16:49:25Z")

</div>

Platform ubuntu 16.04 OS  
Error that I used to get

```auto
matching2D.hpp:16:35: fatal error: opencv2/xfeatures2d.hpp: No such file or directory
 #include <opencv2/xfeatures2d.hpp>

```

The error was resolved by using the following instructions  
1.

```auto
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.1.0
cd .. #get out of opencv folder

```

2.Get opencv-contrib

```auto
https://github.com/opencv/opencv_contrib/
cd opencv_contrib
git checkout 4.1.0
cd .. #get out of opencv_contrib folder

```

3.Install

```auto
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D WITH_GTK=ON ..
make
sudo make install

```

As such how exactly does setting the flag opencv\_enable\_nonfree help in resolving this error?

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [May 28, 2023, 5:04pm UTC](https://forum.opencv.org/t/regarding-setting-flags-while-building-opencv-c/13333/4 "2023-05-28T17:04:34Z")

</div>

Why do you use opencv 4.1.0?

delete content of buid repo (all files)

> <https://github.com/udacity/SFND_2D_Feature_Tracking/issues/3#issuecomment-751512446>
>
> I installed opencv4.1.0 but when I ran the project, I couldn't find xfeatures2d.…hpp. 
> 
> the error is
> \`\`\`
> matching2D.hpp:16:35: fatal error: opencv2/xfeatures2d.hpp: No such file or directory
> #include \<opencv2/xfeatures2d.hpp\>
> ^
> compilation terminated.
> CMakeFiles/2D\_feature\_tracking.dir/build.make:62: recipe for target 'CMakeFiles/2D\_feature\_tracking.dir/src/matching2D\_Student.cpp.o' failed
> make\[2\]: \*\*\* \[CMakeFiles/2D\_feature\_tracking.dir/src/matching2D\_Student.cpp.o\] Error 1
> CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/2D\_feature\_tracking.dir/all' failed
> make\[1\]: \*\*\* \[CMakeFiles/2D\_feature\_tracking.dir/all\] Error 2
> Makefile:83: recipe for target 'all' failed
> make: \*\*\* \[all\] Error 2
> \`\`\`
> What should I do?

---

<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:** [May 28, 2023, 7:19pm UTC](https://forum.opencv.org/t/regarding-setting-flags-while-building-opencv-c/13333/5 "2023-05-28T19:19:07Z")

</div>

> [@opencvnoob](#):
>
> `4.1.0`

any issue must be replicable with most recent release.

if you insist on using an obsolete version, and you get issues that have already been fixed in a newer version, you’re on your own.

---

<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:** [June 5, 2023, 6:00am UTC](https://forum.opencv.org/t/regarding-setting-flags-while-building-opencv-c/13333/8 "2023-06-05T06:00:44Z")

</div>

Closed on June 5, 2023, 6:00am UTC

This topic was automatically closed after 7 days. New replies are no longer allowed.
