错误不能打开源文件“…”

时间:2022-06-02 20:52:54

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(通过dreamspark下载),虽然我可以通过右键单击并按打开文件打开#include文件,但它抱怨“错误不能打开源文件”……这似乎有些荒谬。我这次用Qwt来解决这个问题我有一个问题

#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.

提前谢谢。

3 个解决方案

#1


9  

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.

如Neil所指出的,尝试使用引号代替在文件名周围的<>字符。当使用引号时,MSVC将会在与文件#include相同的目录中查找指定的文件,如果没有找到,则会在包含路径指定的目录中查找。当文件名被<>字符包围时,当前文件的目录没有被查看——编译器会直接进入include路径。

See http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx for 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:

如果这没有帮助,请确保您的include路径通过适当地设置“include目录”属性来包含文件所在的目录:

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项目(我不确定是多么常见的Qt项目继续使用qmake当由VS),在这种情况下,您将需要执行任何使文件中的配置是必要的(s)或在命令行上传递的参数调用makefile。

#2


3  

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++ section ->附加包括目录。

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]

[编辑]当然是尼尔说的[/编辑]

#3


0  

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文件,现在一切正常。

#1


9  

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.

如Neil所指出的,尝试使用引号代替在文件名周围的<>字符。当使用引号时,MSVC将会在与文件#include相同的目录中查找指定的文件,如果没有找到,则会在包含路径指定的目录中查找。当文件名被<>字符包围时,当前文件的目录没有被查看——编译器会直接进入include路径。

See http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx for 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:

如果这没有帮助,请确保您的include路径通过适当地设置“include目录”属性来包含文件所在的目录:

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项目(我不确定是多么常见的Qt项目继续使用qmake当由VS),在这种情况下,您将需要执行任何使文件中的配置是必要的(s)或在命令行上传递的参数调用makefile。

#2


3  

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++ section ->附加包括目录。

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]

[编辑]当然是尼尔说的[/编辑]

#3


0  

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文件,现在一切正常。