使用来自另一个项目(目录)的头文件

时间:2021-10-19 05:31:14

I am using Visual Studio 2008, and I need to use certain header files from another project. I have tried to add the path in "Additional Include Directories" in C/C++ General properties pane, but my project still puts out the same errors

我正在使用Visual Studio 2008,我需要使用来自另一个项目的某些头文件。我试图在C / C ++常规属性窗格的“其他包含目录”中添加路径,但我的项目仍然会发出相同的错误

(fatal error C1083: Cannot open include file: 'tools/rcobject.h'.

All the other cpp and header files I am using I added as existing files from another directory, and for some headers it puts out an error and for others it doesn't. There was no change in errors after adding additional include directories.

我正在使用的所有其他cpp和头文件我作为现有文件从另一个目录中添加,对于某些头文件,它会发出错误,而对于其他文件则不会。添加其他包含目录后,错误没有变化。

Can someone help me, I am stuck as I need to Debug...

有人可以帮助我,因为我需要调试而陷入困境......

2 个解决方案

#1


In the "Additional Include "Directories", did you put the path to the "tools" directory, or the path to the directory that includes the "tools" directory? It needs to be the latter.

在“附加包含”目录中,您是否将路径放到“tools”目录,或者包含“tools”目录的目录的路径?它需要是后者。

How the preprocessor works to resolve #include directives, is to take the path specified in the #include and then append it to each of the paths specified in the "Additional Include Directories" (and some other places specific for the project). So, you need to make sure that the path specified in the "Additional Include Directories" plus the path you gave to the #include exactly matches the path to the file you are trying to include.

预处理器如何解析#include指令,是采用#include中指定的路径,然后将其附加到“Additional Include Directories”(以及特定于项目的其他一些位置)中指定的每个路径。因此,您需要确保“其他包含目录”中指定的路径加上您为#include指定的路径与您尝试包含的文件的路径完全匹配。

For example, suppose you have the following file you want to include:

例如,假设您要包含以下文件:

c:\blah\bletch\foo\bar.txt

Then you did this:

然后你这样做了:

#include "bar.txt"

Then you would need to make sure that "c:\blah\bletch\foo" was in the "Additional Include Directories".

然后你需要确保“c:\ blah \ bletch \ foo”在“其他包含目录”中。

Or if you had done this:

或者如果你这样做了:

#include "foo\bar.txt"

Then you would need to make sure that "c:\blah\bletch" was in the "Additional Include Directories".

然后你需要确保“c:\ blah \ bletch”在“附加包含目录”中。

#2


Enable the build log (I don't know from the top of my head where it is, shouldn't be too hard to find) and see if the paths you specify appear in the compiler command line. If not you're probably doing something wrong. Using additional include directories should just work. Just make sure you're using the right directory separator and you fill them in under the correct configuration (Release/Debug).

启用构建日志(我不知道从哪里开始,不应该太难找到)并查看您指定的路径是否出现在编译器命令行中。如果不是,你可能做错了什么。使用其他包含目录应该可行。只需确保使用正确的目录分隔符,然后在正确的配置(发布/调试)下填写它们。

Regards,

Sebastiaan

#1


In the "Additional Include "Directories", did you put the path to the "tools" directory, or the path to the directory that includes the "tools" directory? It needs to be the latter.

在“附加包含”目录中,您是否将路径放到“tools”目录,或者包含“tools”目录的目录的路径?它需要是后者。

How the preprocessor works to resolve #include directives, is to take the path specified in the #include and then append it to each of the paths specified in the "Additional Include Directories" (and some other places specific for the project). So, you need to make sure that the path specified in the "Additional Include Directories" plus the path you gave to the #include exactly matches the path to the file you are trying to include.

预处理器如何解析#include指令,是采用#include中指定的路径,然后将其附加到“Additional Include Directories”(以及特定于项目的其他一些位置)中指定的每个路径。因此,您需要确保“其他包含目录”中指定的路径加上您为#include指定的路径与您尝试包含的文件的路径完全匹配。

For example, suppose you have the following file you want to include:

例如,假设您要包含以下文件:

c:\blah\bletch\foo\bar.txt

Then you did this:

然后你这样做了:

#include "bar.txt"

Then you would need to make sure that "c:\blah\bletch\foo" was in the "Additional Include Directories".

然后你需要确保“c:\ blah \ bletch \ foo”在“其他包含目录”中。

Or if you had done this:

或者如果你这样做了:

#include "foo\bar.txt"

Then you would need to make sure that "c:\blah\bletch" was in the "Additional Include Directories".

然后你需要确保“c:\ blah \ bletch”在“附加包含目录”中。

#2


Enable the build log (I don't know from the top of my head where it is, shouldn't be too hard to find) and see if the paths you specify appear in the compiler command line. If not you're probably doing something wrong. Using additional include directories should just work. Just make sure you're using the right directory separator and you fill them in under the correct configuration (Release/Debug).

启用构建日志(我不知道从哪里开始,不应该太难找到)并查看您指定的路径是否出现在编译器命令行中。如果不是,你可能做错了什么。使用其他包含目录应该可行。只需确保使用正确的目录分隔符,然后在正确的配置(发布/调试)下填写它们。

Regards,

Sebastiaan