Cenoc
Cenoc

Reputation: 11682

Error can not open source file "..."

I'm using VS2010 (downloaded via dreamspark) and although I can open the #include file by right clicking on it and pressing on Open Document, it complains "Error can not open source file "..."" which seems rather absurd. I'm using Qwt with Qt this time around and I'm specifically having the problem for:

#include <qwt_counter.h> 
#include <qwt_plot.h>

(And I am using the "<>"); not sure how to make those appear properly in the code above.

Thanks in advance.

Upvotes: 3

Views: 34022

Answers (3)

Cenoc
Cenoc

Reputation: 11682

It turned out there was a circular linking happening and I had all my code in a .h file. I split it up and added the corresponding .cpp file, now everything works fine.

Upvotes: 0

Michael Burr
Michael Burr

Reputation: 340426

As Neil indicated, try using quotes instead of the <> characters around the filename. When using the quotes, MSVC will look in the same directory as the file the #include is in for the specified file, then if it's not found there will look in the directories specified by the include path. When the filename is surrounded by <> characters, the current file's directory isn't looked at - the compiler goes right to the include path.

See http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx for details.

Note that this is an implementation dependent behavior - it might not apply to other compilers.

If that doesn't help, make sure that your include path contains the directory that the file is located in by setting the "Include Directories" property appropriately:

Finally, you might be using a makefile project (I'm not sure how common it is for Qt projects to continue to use qmake when built from VS) , in which case you'll need to perform whatever configuration is necessary in the make file(s) or parameters passed on the command line that invokes the makefiles.

Upvotes: 10

jilles de wit
jilles de wit

Reputation: 7148

Is the path where these files are located either the same as that of this source file, or included in the "additional include directories" in your project settings?

Project -> properties -> c/c++ section -> additional include directories.

If they are located in a subdirectory of the source file you're editing or of one of the additional include directories (I think) you can also include them with:

#include <path_to_file_1/qwt_counter.h>
#include <path_to_file_2/qwt_plot.h>

[edit] or of course what neil says [/edit]

Upvotes: 3

Related Questions