21

I've got a problem with include in a qmake project. In my .pro file I've got:

INCLUDEPATH += "C:\OpenCV\build\include"

and in my cpp :

#include <opencv\cv.h>

The compiler indicates an error:

Cannot open include file: 'opencv\cv.h': No such file or directory

but if I write this in my cpp:

#include "C:\OpenCV\build\include\opencv\cv.h"

it works!

I build the project from within Qt Creator. What am I doing wrong?

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
user2794529
  • 259
  • 1
  • 2
  • 6
  • Did you try to set `INCLUDEPATH += "C:\\OpenCV\\build\\include"` and use `#include ` in your source file? – vahancho Sep 27 '13 at 10:10
  • I tried, but it doesn't work... – user2794529 Sep 27 '13 at 10:38
  • 4
    OK I found the solution here : http://stackoverflow.com/questions/14742856/qt-creator-adding-external-library-still-cannot-open-include-file-gl-glew-h I had the rerun qmake -.-' – user2794529 Sep 27 '13 at 10:54
  • @user2794529> Could you please accept an answer? – Liviu Mar 17 '17 at 13:31
  • This question just saved my bacon: INCLUDEPATH += "C:\some\dir" in .pro, #include , delete build- directory, qmake, and rebuild project. –  Jul 19 '17 at 12:22

12 Answers12

17

You have to run qmake(build->run qmake) to validate changes in the pro file. Qt creator Adding external library (still: Cannot open include file: 'GL/glew.h')

Flu2fy Unicorn
  • 171
  • 1
  • 3
9

Your problem may be related to the fact that having backslashes in naked #include directives is undefined behavior.

Do the following.

  1. Replace your include with

    #include <opencv/cv.h>
    

    Note the forward slash!

  2. Remove the shadow build directory that Qt Creator has made for you. You will find it above the project directory, its name begins with build-.

  3. Rebuild the project.

Note that this takes care of rerunning qmake.

Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
3

here's one of my pro files:

    # Blah Application

TEMPLATE  = app
CONFIG   += qt console staticlib debug_and_release
QT       -= gui
QT       += network sql xml
TARGET    = blah

CONFIG(debug, debug|release){
    DESTDIR = debug
    LIBS += -L../../../lib/core/debug -lcore
} else {
    DESTDIR = release
    LIBS += -L../../../lib/core/release -lcore
}
DEPENDPATH  += . ../../lib ../../../lib/core
INCLUDEPATH += . ../../lib ../../../lib/core

# Library files
HEADERS += mtBlahRTP.h
SOURCES += mtBlahRTP.cpp

# Input
HEADERS +=
SOURCES += main.cpp

The include path points to the RELATIVE directory of my lib files. mtBlahRTP.h and mtBlahRTP.cpp are in ../../lib

ldgorman
  • 1,553
  • 1
  • 14
  • 39
3

I have the same question, before building or running, you should qmake(Build=>qmake) it.

My configurations for INCLUDEPATH:

INCLUDEPATH+=D:\opencv\opencv\build\include
INCLUDEPATH+=D:\opencv\opencv\build\include\opencv
INCLUDEPATH+=D:\opencv\opencv\build\include\opencv2
pringi
  • 3,987
  • 5
  • 35
  • 45
  • When using multiple line `INCLUDEPATH`'s, make sure you use `+=` (not `=`) - as I just found out to my cost – Anonymouse Feb 25 '19 at 10:56
1

I ran into a similar issue and what I found is that the QtCreator IDE is not re-reading the results of qmake and updating the "Cannot open" message. You need to close the offending file and re-open it - then you'll see that it no longer displays the error.

1

I had to do two steps: (re-)run qmake and rebuild the whole project - only then the INCLUDEPATH setting was considered correctly. (With QtCreator 3.5 and 3.6 (Qt 5.5 and Qt 5.6) on Windows.)

Dynamo72
  • 31
  • 2
1

The only problem you are making is incorrectly linking the OpenCV library. The other answers given here may or may not work, but I have posted on another thread a surefire way to solve this problem using the "Add Library" wizard inside Qt Creator: https://stackoverflow.com/a/51914928/10245006

0

I was getting the error:

canserialcomm.o: In function `CanSerialComm::CanSerialComm()':
canserialcomm.cpp:(.text+0xc1): undefined reference to `vtable for CanSerialComm'

It turns out that the cause was it wasn't able to find canserialcomm.h where that constructor is declared. This was despite me having INCLUDEPATH in the project file point to the directory containing that header file:

INCLUDEPATH += . \
        ..

What I had to do to fix this is explicitely specify the header file; I added:

HEADER += ../canserialcomm.h
demonplus
  • 5,613
  • 12
  • 49
  • 68
DBedrenko
  • 4,871
  • 4
  • 38
  • 73
0

You should use double backslashes when in windows for qt creator with msvc. like this: INCLUDEPATH += C:\\libcurl\\libcurl-vc-x64-release-dll-ipv6-sspi-winssl\\include

this will fix the problem.

Raiden Core
  • 1,535
  • 12
  • 13
0

Under windows you have to eliminate the -I before each directory that is added into the INCLUDEPATH variable. For example: Under windows:

INCLUDEPATH += "C:\lib\boost_1_61_0" (back-slash)

Under linux & mac:

INCLUDEPATH += -I"$$(HOME)/lib/boost_1_61_0" (note the -I and forward-slash)

I'm not sure whether it depends on different qmake version or not. But after finishing qmake command, I check the Makefile and the double -I is the issue.

Brian Ng
  • 1,005
  • 12
  • 13
0

You need to do several things. Fist, in the .pro file, you need quotation marks two backslashes at a time, like this:

INCLUDEPATH += "C:\\OpenCV\\build\\include\\opencv\\cv.h"

You alse need a frontslash in the #include in your .cpp file like this:

#include <opencv/cv.h>

When you've done this, delete the build folder. This is the folder with a very complicated name of the type build-untitled-Desktop_Qt_5_7_0_MSVC2015_32bit-Release. Then, in the Build menu, press "Run qmake". When you've done all this, it should compile fine.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
0

Somehow it did not work for when I had several INCLUDEPATH +=. When I combined the stuff into a single on it suddenly worked.

Slava
  • 1,528
  • 1
  • 15
  • 23