C++ 错误无法打开源文件“...”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2974908/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error can not open source file "..."
提问by Cenoc
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:
我正在使用 VS2010(通过 Dreampark 下载),虽然我可以通过右键单击它并按下 Open Document 来打开 #include 文件,但它抱怨“错误无法打开源文件“...”,这似乎很荒谬。这次我将 Qwt 与 Qt 一起使用,我特别遇到了以下问题:
#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.
提前致谢。
回答by Michael Burr
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.
正如尼尔指出的那样,尝试使用引号而不是<>
文件名周围的字符。使用引号时,MSVC 将在与#include
指定文件所在的文件相同的目录中查找,然后如果找不到,则会在包含路径指定的目录中查找。当文件名被<>
字符包围时,不会查看当前文件的目录 - 编译器直接转到包含路径。
See http://msdn.microsoft.com/en-us/library/36k2cdd4.aspxfor details.
有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx。
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.
最后,您可能正在使用 makefile 项目(我不确定qmake
从 VS 构建时Qt 项目继续使用的普遍程度),在这种情况下,您需要在 make 文件中执行任何必要的配置( s) 或在调用 makefile 的命令行上传递的参数。
回答by jilles de wit
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.
项目 -> 属性 -> c/c++ 部分 -> 附加包含目录。
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]
[编辑] 或者当然是尼尔所说的 [/编辑]
回答by Cenoc
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.
结果发现发生了循环链接,我的所有代码都在一个 .h 文件中。我将其拆分并添加了相应的 .cpp 文件,现在一切正常。