如果我使用“test.h”,则包含在其中与“path/test.h”相同吗?
我在c++语言下的ubuntu中工作。
我有一个问题:我使用 #include"header.h"
。这与 /path/header.h
相同吗?我问你这个问题是因为据我所知,这不是一回事。需要一些解释。
我问你这个问题是因为我已经在我的计算机上下载并安装了 gsoap。我在一个文件夹中添加了所有必要的依赖项,并且尝试在另一台计算机上运行该应用程序而不安装 gsoap ...。我有一些错误..我忘记添加 stdsoap2.h 文件...我今天将其添加..在我的文件夹中..
I am working in ubuntu under c++ language.
I have a question: i use #include"header.h"
. Is this the same with /path/header.h
? I ask you this question because as I've seen is not the same thing. Need some explications.
I ask you this question because I've downloaded and install gsoap on my computer. I added all the necessary dependencies in a folder and I've tried to run the app without installing gsoap ...on a different computer. I had some errors..i forgot to add stdsoap2.h file...I will add it today..in my folder..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案是这取决于:
如果您将“path/”添加到您的包含路径中,那么仅包含“header.h”将起作用,因为编译器已经知道查找头文件的路径,如果不是
那么你必须包含整个路径“path/header.h”,以便编译器知道在哪里查找头文件。
The answer is it depends:
If you have "path/" added to your include path then including only "header.h" will work because then compiler already knows the path to lookup for your header files, if not
then you have to include entire path "path/header.h" so the compiler knows where to look for the header file.
如果
header.h
位于目录path/
中,则#include "header.h"
将适用于这些头文件和源文件(其中#include
header.h 恰好与header.h
(path/
) 位于同一目录中。正在
#include
-ingheader.h
位于与path/
不同的目录中的文件中,那么上述方法将不起作用,您可以尝试 2 种不同的方法:#include
header.h
的完整路径如下所示:#include "path/header.h"
path/
目录包含到makefile
中。这也会让g++
在这些目录中查找header.h
。这可以像这样完成(在 makefile 中):g++ <一些参数> -Ipath/ -c main.cpp -o main.o
(假设从main.cpp
中调用header.h
)。如果您选择这种方式,那么#include
也会发生变化,如下所示:#include
。请注意使用-I
标志作为 g++ 的参数。该标志告诉 g++ 也查看其他目录。If
header.h
is in the directorypath/
, then#include "header.h"
will work for those header and source files (which#include
header.h which happen to be in the same directory asheader.h
(path/
).On the other hand, if you are
#include
-ingheader.h
in a file that is in a different directory thanpath/
, then the above way would not work. To make it work, you can try 2 different approaches:#include
the complete path toheader.h
. Your#include
will look something like:#include "path/header.h"
path/
directory to themakefile
. This will getg++
to look forheader.h
in those directories as well. This can be done like so (in the makefile):g++ <some parameters> -Ipath/ -c main.cpp -o main.o
(assumingheader.h
is called from withinmain.cpp
). If you choose this way, then the#include
will also change, like so:#include <header.h>
. Note the use of the-I
flag as a parameter to g++. That flag tells g++ to look into additional directories as well.不,它们在概念上并不相同。然而,结果可能是一样的。这取决于您如何告诉编译器查找标头(
g++
中的-I
标志)。如果您使用-I /path/
进行编译,那么您会发现/path/header.h
带有#include "header.h"
>。如果您不使用包含路径标志,则必须编写#include "/path/header.h"
。No, they are not the same, conceptually. The results, however, could be the same. It depends on how you tell your compiler to find headers (the
-I
flag ing++
). If you would compile with-I /path/
, then you'd find/path/header.h
with#include "header.h"
. If you do not use that include path flag, then you'd have to write#include "/path/header.h"
.