in include if i use "test.h" is the same with "path/test.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开发者_Python百科 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..
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.
If header.h
is in the directory path/
, then #include "header.h"
will work for those header and source files (which #include
header.h which happen to be in the same directory as header.h
(path/
).
On the other hand, if you are #include
-ing header.h
in a file that is in a different directory than path/
, 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"
- Include the
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.
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 in g++
). 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"
.
精彩评论