c++ - 库里面实现文件与头文件的问题
PHP中文网
PHP中文网 2017-04-17 14:44:52
0
2
557

在github上看到一个项目,其中lib目录下的实现文件包含有另一个head文件夹下的头文件。lib文件夹和head文件夹不是同级的文件夹,head文件夹是另一个文件夹的子文件夹。但是lib文件夹里面的实现文件直接以#include "head/xx.hpp"的方式包含着头文件的。想知道为什么可以这样包含,lib下的实现文件如何能够访问到那个头文件呢?
先谢谢大家了

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
刘奇

At this time, you should use the -I parameter in gcc. For example, your head/xxx.h position is in /path/to/libs/head/xxx.h, and when drinking, use #include "head/xxx.h". Just compile with the following parameters:

gcc lib/xxx.c -I/path/to/libs

man gcc is as follows:

-I dir
     Add the directory dir to the list of directories to be searched for
     header files.  Directories named by -I are searched before the
     standard system include directories.  If the directory dir is a
     standard system include directory, the option is ignored to ensure
     that the default search order for system directories and the
     special treatment of system headers are not defeated .  If dir
     begins with "=", then the "=" will be replaced by the sysroot
     prefix; see --sysroot and -isysroot.
左手右手慢动作

There should be a configuration option that sets the previously omitted path prefix. Clone the project, use sublime or something to globally search for the missing path characters, and you will know where it is configured.
Normally when you write a program, the previous #include<stdio.h> is not placed in the currently visible directory. The Linux system has some default environment variables like C_INCLUDE_PATH, which store some system paths. These paths are the header file paths that will be searched by default when you include. You can continue to add your own path later.
I don’t know what platform your project is on. Like Android, when compiling jni, just use LOCAL_C_INCLUDES to specify the header file path, and the long header file path can be omitted from the code. .
You can also search for keywords linux system header file search path and so on to learn relevant knowledge.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template