# OpenCV build from source error

**URL:** <https://forum.opencv.org/t/opencv-build-from-source-error/14616>\
**Category:** C++\
**Tags:** build, xfeatures2d, contrib\
**Created:** [September 22, 2023, 11:13am UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616 "2023-09-22T11:13:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfatih7](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mfatih7](https://forum.opencv.org/u/mfatih7)\
**Post date:** [September 22, 2023, 11:13am UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/1 "2023-09-22T11:13:14Z")

</div>

Hello

I am trying to build OpenCV 4.7 and 4.8 from source code using CMAKE GUI.  
If I build without setting OPENCV\_EXTRA\_MODULES\_PATH the CMAKE build and generate succeeds and in Visual Studio I can build and install without any error.

But when I set OPENCV\_EXTRA\_MODULES\_PATH CMAKE build and generate again succeeds but I get the following errors in Visual Studio.

69\>cmake\_pch.obj : error LNK2019: unresolved external symbol "public: virtual class std::basic\_string\<char,struct std::char\_traits,class std::allocator \> …  
69\>D:\opencv\_from\_source\python3\_10\opencv-4.7.0\build\bin\Release\opencv\_xfeatures2d470.dll : fatal error LNK1120: 1 unresolved externals  
69\>Done building project “opencv\_xfeatures2d.vcxproj” – FAILED.

166\>cv2.obj : error LNK2019: unresolved external symbol "public: virtual class std::basic\_string\<char,struct std::char\_traits,class std::allocator \> …  
166\>D:\opencv\_from\_source\python3\_10\opencv-4.7.0\build\lib\python3\Release\cv2.cp310-win\_amd64.pyd : fatal error LNK1120: 1 unresolved externals  
166\>Done building project “opencv\_python3.vcxproj” – FAILED.

When I observe the build directory I see that opencv\_xfeatures2d470.dll and cv2.cp310-win\_amd64.pyd are not generated by CMAKE.

Can anyone tell what my error is?

best regards

---

<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:** [September 22, 2023, 11:42am UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/2 "2023-09-22T11:42:23Z")

</div>

> [@mfatih7](#):
>
> But when I set OPENCV\_EXTRA\_MODULES\_PATH CMAKE build and generate again succeeds but I get the following errors in Visual Studio.

- please make sure, to use **EXACTLY** same versions for both. best try latest master(4.x) for **both**. don’t mix with 4.7
- clean build folder and start _all over_ with this
- if you mainly want python bindings, use BÙILD\_SHARED\_LIBS=OFF` cmake flag, to build _static_ libs, so the cv2.pyd wont depend on further opencv dlls at runtime

---

<div class="post-metadata">

**Author:** ![mfatih7](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mfatih7](https://forum.opencv.org/u/mfatih7)\
**Post date:** [September 22, 2023, 11:42am UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/3 "2023-09-22T11:42:56Z")

</div>

Hi

I am working on an environment without an internet connection.  
When I examine CMAKE configure logs I see that xfeatures2d/vgg tries to download opencv\_3rdparty but it becomes unsuccessful.

Should I also include opencv 3rd party packages to CMAKE?

---

<div class="post-metadata">

**Author:** ![mfatih7](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mfatih7](https://forum.opencv.org/u/mfatih7)\
**Post date:** [September 22, 2023, 11:46am UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/4 "2023-09-22T11:46:34Z")

</div>

Hello

Thank you for the answer

- With OpenCV 4.8 I observe the same errors.
- I am inserting all my configuration parameters using “+Add Entry” button of CMAKE GUI when the build folder is empty.

---

<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:** [September 22, 2023, 12:03pm UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/5 "2023-09-22T12:03:01Z")

</div>

> [@mfatih7](#):
>
> I am working on an environment without an internet connection.

that’s bad. gapi/ade ffmpeg(video support) xfeatures2d and more wont work.

at least you can disable xfeatures2d (& resp. download) with

```
BUILD_opencv_xfeatures2d=OFF

```

so it wont get in your way linking the cv2.pyd

> [@mfatih7](#):
>
> Should I also include opencv 3rd party packages to CMAKE?

what do you mean ? “include” like what ?

---

<div class="post-metadata">

**Author:** ![mfatih7](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mfatih7](https://forum.opencv.org/u/mfatih7)\
**Post date:** [September 22, 2023, 2:16pm UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/6 "2023-09-22T14:16:46Z")

</div>

Sorry for my poor-quality expression.  
I just want to learn if it is possible to involve 3rd party packages to build process like we do for opencv\_contrib with OPENCV\_EXTRA\_MODULES\_PATH option?

My main motivation for building opencv from source code is using SURF feature extraction method.

Is there any way for a PC without a net connection to build opencv\_contrib with the enabled OPENCV\_ENABLE\_NONFREE option?

Can I build and generate using CMAKE and build all using Visual studio in another PC and transfer the build folder to my actual PC for installation using Visual Studio?

---

<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:** [September 22, 2023, 2:24pm UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/7 "2023-09-22T14:24:45Z")

</div>

> [@mfatih7](#):
>
> Can I build and generate using CMAKE and build all using Visual studio in another PC

sounds like an idea.  
run cmake once on pc1, let it do the downloads,  
then transfer to pc2, and do your VS configuration there

note, that it actually downloads to `opencv/.cache`, so you’ll need to transfer that, too.

---

<div class="post-metadata">

**Author:** ![mfatih7](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mfatih7](https://forum.opencv.org/u/mfatih7)\
**Post date:** [September 22, 2023, 2:56pm UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/8 "2023-09-22T14:56:45Z")

</div>

What about the Python interpreter versions and Visual Studio versions.  
I think both PCs must have same python interpreter versions, the same Visual Studio editions?

I will give more feedback. But, I think after I set BÙILD\_SHARED\_LIBS=OFF Visual Studio build errors about opencv\_xfeatures2d470.dll and cv2.cp310-win\_amd64.pyd disappeared.  
Do you tell that even if the errors are disappeared I can not use features2d?

---

<div class="post-metadata">

**Author:** ![mfatih7](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mfatih7](https://forum.opencv.org/u/mfatih7)\
**Post date:** [September 25, 2023, 11:26am UTC](https://forum.opencv.org/t/opencv-build-from-source-error/14616/9 "2023-09-25T11:26:57Z")

</div>

Hello @berak

Here are the steps to build OpenCV with CMAKE and Visual Studio from source code on a machine with Internet connection and transfer build to a machine without Internet connection.

1- Download compatible opencv and opencv-contrib packages and CMAKE.  
2- Generate a Conda environment with Python version of destination machine.  
3- On CMAKE GUI select opencv folder and a build folder.  
4- Using “+Add Entry” option on CMAKE GUI set  
PYTHON3\_EXECUTABLE, PYTHON3\_INCLUDE\_DIR, PYTHON3\_LIBRARY according to the Conda environment generated  
5- Using “+Add Entry” option on CMAKE GUI activate OPENCV\_ENABLE\_NONFREE  
6- Using “+Add Entry” option on CMAKE GUI set OPENCV\_EXTRA\_MODULES\_PATH  
7- Click Configure and select the destination machine operating system and Visual Studio version.  
8- Configure till all of the parameters that are marked as red disappear.  
9- Click Generete.  
10- Open .sln file on the build folder using Visual Studio.  
11- On Visual Studio select Release.  
12- Under CMakeTargets right click ALL\_BUILD and select build.  
13- If there are no errors right click INSTALL and select build.  
14- Under the Python environment find cv2 folder and copy these python bindings to destination machine.  
15- Under build folder copy install folder to destination machine  
------------Destination Machine----------------------------------------------------------------  
16- Copy python bindings to my\_env/Lib/site packages  
17- Copy the install folder to a proper destination on destination machine  
18- Under cv2 file update the paths in config.py and config-3.10.py files with respect to the folder locations on destination machine  
19- Using the Python environment test OpenCV functions

thank you
