【问题标题】:for c/cpp include path by adding the path to system file and run通过添加系统文件的路径并运行 c/cpp 包含路径
【发布时间】:2020-02-21 10:38:35
【问题描述】:

~/test 中名为 test.cpp 的文件 代码是

#include <stdio.h>
#include "add.h" 
int main(){
    printf("%d\n",add(1,2));
}

文件add.h在~/test/1,只是一个子目录

代码是

int add(int a, int b){return a+b;}

然后我使用导出

export PATH=$PATH:~/test/1

有什么办法可以解决吗?

不使用#include "1/test"

非常感谢任何帮助

【问题讨论】:

标签: c++ c gcc path export


【解决方案1】:

export 用于为 shell 创建环境变量。它与编译器查找包含文件的位置无关。

gcc -Itest/1 test.cpp 应该让它工作。 -I 参数为 gcc 提供了在其中查找包含文件的路径。

如果您愿意,可以使用 makefilecmake 将这些特定指令提供给 gcc。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    相关资源
    最近更新 更多