Ask Your Question
0

Error: 'Cannot open source file "XXXXX.hpp"' but app still building and working!

asked 2014-09-11 10:25:22 -0600

Doombot gravatar image

updated 2014-09-11 13:13:30 -0600

So I installed OpenCV 2.4.9 on a new computer and followed the various steps to link it's dll/lib in Visual Studio 2012 C++, as provided in the doc.

Using the sample code in the doc (copy/paste), the #include "opencv2\highgui\highgui.hpp" and all others opencv related includes are underlined in red, as well as every mention of opencv function/vars in the code. The error provided is "Cannot open source file "XXXXXXX.hpp", which is strange since I followed all the steps (even replacing the version number of the libs).

Stranger is that I compile and no error, run the example program from the command line and it works correctly.

So I started a new solution and tried to build another sample program. Again, same error in the IDE and the program builds just fine.

Anyone ever had a similar problem? In the past, when this kind of error happened, I was simply unable to build the app.

edit retag flag offensive close merge delete

Comments

Maybe the compiler is more forgiving or searching more agressive than Visual Studio. This is most likely a include path setting not (correctly) set in VS.

boaz001 gravatar imageboaz001 ( 2014-09-12 02:24:39 -0600 )edit

True, the problem was from the path. I will answer below

Doombot gravatar imageDoombot ( 2014-09-12 08:57:16 -0600 )edit

I will answer as soon as possible. The short answer is I used %OPENCV_DIR% (the Windows way) in my path setting of Visual Studio instead of $(OPENCV_DIR) or %(OPENCV_DIR). I assume that when Windows executed the program, it just saw %OPENCV_DIR% and knew what it meant, while Intellisense just could not understand.

Doombot gravatar imageDoombot ( 2014-09-12 09:02:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-15 08:03:54 -0600

Doombot gravatar image

OK, I thought about it and found the culprit:

I am using a Windows Environment Variable, namely %OPENCV_DIR% , in my linkers/include pathway in Visual Studio. It appears that while this "syntax" (%VAR_NAME%) is correct in Windows itself, Visual Studio 2012 requires one of the following syntax (complete explanation of the syntax on http://msdn.microsoft.com/en-us/library/669zx6zc.aspx)

Global macros Applies to all items in a project configuration. Has the syntax $(name).

$(OPENCV_DIR)\folder1\file1.hpp

Item macros Has the syntax %(name). For a file, an item macro applies only to that file.

%(OPENCV_DIR)\folder1\file1.hpp

So, Visual Studio could not find the include header because to him, %OPENCV_DIR%\folder1\file1.hpp was simply a regular pathway.

edit flag offensive delete link more

Comments

HYPOTHESIS: Somehow, since the program uses a .dll , it seems that during its execution, Windows could find the correct path to the folder because %OPENCV_DIR%\folder1\file1.hpp was "understandable".

Doombot gravatar imageDoombot ( 2014-09-15 08:04:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-09-11 10:25:22 -0600

Seen: 3,694 times

Last updated: Sep 15 '14