如何避免在C或C ++ #include指令中明确声明目录路径? [英] How can I avoid explicitly declaring directory paths in C or C++ #include directives?

查看:84
本文介绍了如何避免在C或C ++ #include指令中明确声明目录路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个模拟器,并写了很多文件和头文件.问题是,每当我包含文件时,我都会给出特定文件的相对路径.例如,我的应用程序中的典型代码将以

I am making a simulator and have written lots of files and headers. The problem is whenever I include a file I give the relative path of the particular file. For example a typical code in my application would begin like

#ifndef AI_H
#define AI_H

#include <cstdlib>

#include "../world/world.h"
#include "pathPlan.h"
#include "skills/tryskill.h"
#include "../info/condition.h"
#include "dataStructures/destination.h"
#include "../params/gamePlay.h"
#include "../modules/controlModule.h"


class ai
{
    public:

etc etc

我想避免使用相对路径.例如,我想直接包含"tryskill.h"和"destination.h",而不给出绝对路径.这样,如果我更改任何特定文件的位置,就无需打扰.我正在使用Ubuntu 9.10.任何帮助将不胜感激.

I want to avoid using the relative paths. For example I want to directly include "tryskill.h" and "destination.h" without giving the absolute paths. That way I wont need to bother if I change the location of any particular file. I am using Ubuntu 9.10. Any help would be highly appreciated.

推荐答案

真的,这完全取决于您的include路径,不同的编译器可能在gcc中称其为不同的东西

Really it all depends on your include path, different compilers might call it different things but in gcc

-Idir  Append directory dir to the list of directories searched for include files.

因此在您的示例中,您将在-I

So in your example you would specify ../world etc... in the list of directories in -I

这篇关于如何避免在C或C ++ #include指令中明确声明目录路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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