1

Every time I try to compile this code in OpenCV, I keep getting this error. All I want to do is create a window:

//#include <iostream>
//#include <stdio.h>
#include "highgui.h"

int main() {
    int cvNamedWindow(const char* name, int flags = CV_WINDOW_AUTOSIZE);
    {
        cvNamedWindow("sample");
    }
    cvDestroyWindow("sample");    
}

However I'm getting this error:

window.cpp:4:21: fatal error: highgui.h: No such file or directory

I have checked in the necessary folder and highgui.h is very much installed.

Any help?

6
  • What are your include directories? Commented Feb 2, 2013 at 18:50
  • they are in my opencv folder Commented Feb 2, 2013 at 18:59
  • Your compiler has a list of directories called "Include directories", where it will search for the header files. You need to put OpenCV's include directory in that list. Otherwise the compiler won't fint the header. Commented Feb 2, 2013 at 19:24
  • I'm using the 'g++' compile command. What would the compile folder be called? Commented Feb 2, 2013 at 19:32
  • gcc.gnu.org/onlinedocs/cpp/Search-Path.html Commented Feb 2, 2013 at 19:47

2 Answers 2

1

Include files as following

#include "opencv2/highgui/highgui.hpp"

And compile the file

g++ -ggdb `pkg-config --cflags opencv` filename `pkg-config --libs opencv`
Sign up to request clarification or add additional context in comments.

4 Comments

Getting this error:window.cpp:5:41: fatal error: opencv2/highgui/highgui.h.hpp: No such file or directory compilation terminated.
What platform are you using? Windows or Linux? How did you install OpenCV? through package manager or compiled it?
can you check /usr/local/lib and /usr/lib for OpenCV files?
I'm using Ubuntu 12.04 and i have checked both directories and the opencv files are there
1

If you have the OpenCV include as part of the include path, it should be

#include "opencv/highgui.h"

or

#include "opencv2/highgui/highgui.hpp"

depending on you using the c or c++

3 Comments

i'm using C, so the first one?
Grrr even after showing using this compile command g++ -o window window.cpp -I/usr/include/opencv I'm now getting this error!: window.cpp:(.text+0xf): undefined reference to cvNamedWindow' window.cpp:(.text+0x19): undefined reference to cvDestroyWindow'
The unnamed references is because the linker can't find the library or you're not telling which library to use, mainly "opencv_highgui243d.lib". Currently using windows and not linux. But works when I add the following libraries. opencv_core243d.lib, opencv_highgui243d.lib, comctl32.lib, zlibd.lib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.