简体   繁体   English

要包含来自另一个目录的文件?

[英]To include a file from another Directory?

I know the path of a file which is in another directory.我知道另一个目录中文件的路径。 How can I be able to access the file's functions from another directory?我怎样才能从另一个目录访问文件的功能?

Compiler: gcc compiler编译器:gcc编译器
Distributor ID: Ubuntu经销商编号:Ubuntu
Description: Ubuntu 20.04.4 LTS说明:Ubuntu 20.04.4 LTS
Release: 20.04发布:20.04
Codename: focal代号:焦点
Kernel: 5.10.102.1-microsoft-standard-WSL2 Kernel:5.10.102.1-微软标准-WSL2

2 different ways to accomplish this 2种不同的方法来完成这个

1: pass -I./dirName to the compiler and add #include <filename.h> to the source file. 1:将-I./dirName传递给编译器,并在源文件中添加#include <filename.h> -I means to include a directory that will reference.h files, and <> in C is used to indicate that we want to grab from an included directory. -I表示包含一个将引用.h文件的目录,C中的<>表示我们要从一个包含的目录中抓取。

2: Add #include "../filename.h" to the source code to include a header file from another directory. 2:在源代码中添加#include "../filename.h"以包含来自另一个目录的 header 文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM