如何将目录永久添加到 GCC 包含搜索路径?
我运行的是 OSX 10.6.6。我已经安装了Apples GCC-版本4.2.1。我正在为自己编写一个不错的小库——用于调试、数据存储算法等。我已将所有头文件和 .c 文件存储在 C 文件夹中一个名为“mylib”的漂亮小文件夹中。我想将该文件夹添加到 GCC 搜索路径中,这样我就可以输入
/* ... */
#include <mylib/debug.h>
/* ... */
并使其完美运行。如何将 /Users/Henry/coding_stuff/c/include/mylib 添加到 GCC 搜索路径,或者引用 /usr/include 中的文件夹?我不想每次进行微小的更改时都将 /usr/include/mylib 替换为 C 文件夹中的那个。那么,如何才能做到呢?
I'm running OSX 10.6.6. I have installed Apples GCC- version 4.2.1. I'm writing myself a nice little library- things for debugging, data storage algorithms, and the like. I've stored all the headers and .c files in a nice little folder called 'mylib' in my C folder. I'd like to add that folder to the GCC search path, so that I can type, say,
/* ... */
#include <mylib/debug.h>
/* ... */
and have it work perfectly. How can I either add /Users/Henry/coding_stuff/c/include/mylib to the GCC search path, or have a reference to the folder in /usr/include? I'd like to not have to replace /usr/include/mylib with the one in my C folder every time I make a trivial change. So, how can it be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
符号链接将起作用:
解决此问题的更传统方法是使用编译器的
-I
标志来添加搜索路径:A symbolic link will work:
A more traditional way to solve this problem is to use the compiler's
-I
flag to add your search path:添加到您的
.bashrc
:Add to your
.bashrc
:您需要将环境变量 LD_LIBRARY_PATH 设置为等于路径。最有可能在你的 .bashrc 中。
抱歉,这实际上应该是构建的 LIBRARY_PATH ; LD_LIBRARY_PATH 用于运行时库链接。
You need to set the environment variable LD_LIBRARY_PATH to equal the path. Most likely in your .bashrc.
Sorry this should actually be LIBRARY_PATH for the build; LD_LIBRARY_PATH is for runtime library linking.
我使用的是 Ubuntu14.04 和 gcc。
gcc 将
C_INCLUDE_PATH
添加到搜索目录列表中。您可以使用
-v
选项来查看 gcc 实际搜索的位置。(
INCLUDE_PATH
对我不起作用。)因此,您可以将以下内容添加到
.bashrc
:我找到了官方文档:https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
I'm using Ubuntu14.04 and gcc.
gcc adds
C_INCLUDE_PATH
to the list of search directories.You can use
-v
option to see where gcc actually searchs.(
INCLUDE_PATH
does not work for me.)So, you can add the following to
.bashrc
:I found the official documentation: https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html