4
votes

While building a simple OpenCV app in VS2015 I am getting error 'cv': a namespace with this name does not exist while building while I believe I did all the required steps to configure OpenCV for VS (using this article as reference http://opencv-srf.blogspot.com/2013/05/installing-configuring-opencv-with-vs.html)

Beginning of the class is very simple

#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/stitching.hpp"
#include "opencv2/core/core.hpp"
#include "stdafx.h"

using namespace std;
using namespace cv;

Since Visual Studio doesn't throw any errors on #include I assume the configuration in the C/C++ -> General -> Additional Include Directories is correct.

In Linker -> General -> Additional Library Dependencies I have the opencv\build\x64\vc14\build\lib folder added.

In Linker -> Input -> Additional Dependencies I have the following two libs:

opencv_world320.lib
opencv_world320d.lib

There is nothing else in this folder. Folder opencv/build/x64/vc14/bin is added to PATH.

Any suggestions what to check/change is appreciated :)

1
Sure, you included the headers correctly? Double check it, there should be the source of error.Armen Avetisyan
After replacing#include "opencv2/core/core.hpp" with #include "opencv2/opencv.hpp"' I get warning "#include "opencv2/opencv.hpp"': skipped when looking for precompiled header use". Also there is a ton of errors related to xtr1common...Lech Migdal

1 Answers

11
votes

I had this problem as well, and the solution was maddeningly simple:

The #include "stdafx.h" must be the first #include.

The example that the OpenCV folks provide does not mention this, even when they're providing an example for doing this specifically with visual studio.