c++ - 库里面实现文件与头文件的问题

查看:97
本文介绍了c++ - 库里面实现文件与头文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

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

解决方案

这时候就该用gcc里的-I参数,比如你的head/xxx.h位置在/path/to/libs/head/xxx.h,而饮用时用#include "head/xxx.h",用以下参数编译即可:

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

man gcc如下:

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

这篇关于c++ - 库里面实现文件与头文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆