# How to build OpenCV Without Visual Studio

**URL:** <https://forum.opencv.org/t/how-to-build-opencv-without-visual-studio/17629>\
**Category:** C++\
**Tags:** build\
**Created:** [May 12, 2024, 9:12pm UTC](https://forum.opencv.org/t/how-to-build-opencv-without-visual-studio/17629 "2024-05-12T21:12:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheIluvatari](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@TheIluvatari](https://forum.opencv.org/u/TheIluvatari)\
**Post date:** [May 12, 2024, 9:12pm UTC](https://forum.opencv.org/t/how-to-build-opencv-without-visual-studio/17629/1 "2024-05-12T21:12:47Z")

</div>

I’m using VSCode, CMake v 3.27, GCC13.2 (x86\_64-w64-mingw32), OpenCV 4.9 Windows downloaded and installed from [here](https://opencv.org/releases/). My toolchain works for a handful of other c++ projects I work on.

From what I can tell, I need to use find\_package (though I’d far prefer to add\_subdirectory and build it directly from source as a subproject like I would most other libs. Is there a reason I can’t do that?)

```auto
cmake_minimum_required(VERSION 3.27)
project("testcv")
set(OpenCV_DIR "~/openvc/opencv-4.9.0/build/")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

```

My CMake mostly works, in that it’s no longer complaining on an inability to find OpenCV since I added OpenCV\_Dir. Now CMake configures properly, but on build fails as:

> No rule to make target ‘~/openvc/opencv-4.9.0/build/lib/libopencv\_gapi490.dll.a’, needed by ‘testcv.exe’

Or in VS build tools,

> INK : fatal error LNK1104: cannot open file ‘~\openvc\opencv-4.9.0\build\lib\libopencv\_gapi490.dll.a’

My Main file is trivial, really just contains an

```auto
#include <opencv2/opencv.hpp>

```

I’m not clear what I’m missing, and admittedly I found the OpenCV build documentation very unhelpful. I’ve tried a few different iterations of my CMakeLists and I’m not sure what else to try. Any help would be great appreciated!
