如何将目录永久添加到 GCC 包含搜索路径?

发布于 2024-10-28 04:22:41 字数 396 浏览 0 评论 0原文

我运行的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

若相惜即相离 2024-11-04 04:22:41

符号链接将起作用:

sudo ln -s /Users/Henry/coding_stuff/c/include/mylib /usr/include/mylib

解决此问题的更传统方法是使用编译器的 -I 标志来添加搜索路径:

gcc -I /Users/Henry/coding_stuff/c/include/mylib -c -o example.o example.c

A symbolic link will work:

sudo ln -s /Users/Henry/coding_stuff/c/include/mylib /usr/include/mylib

A more traditional way to solve this problem is to use the compiler's -I flag to add your search path:

gcc -I /Users/Henry/coding_stuff/c/include/mylib -c -o example.o example.c
迷爱 2024-11-04 04:22:41

添加到您的 .bashrc

export INCLUDE_PATH=/Users/Henry/coding_stuff/c/include/mylib

Add to your .bashrc:

export INCLUDE_PATH=/Users/Henry/coding_stuff/c/include/mylib
执妄 2024-11-04 04:22:41

您需要将环境变量 LD_LIBRARY_PATH 设置为等于路径。最有可能在你的 .bashrc 中。

export LD_LIBRARY_PATH=/path/to/libs

抱歉,这实际上应该是构建的 LIBRARY_PATH ; LD_LIBRARY_PATH 用于运行时库链接。

export LIBRARY_PATH=/path/to/libs

You need to set the environment variable LD_LIBRARY_PATH to equal the path. Most likely in your .bashrc.

export LD_LIBRARY_PATH=/path/to/libs

Sorry this should actually be LIBRARY_PATH for the build; LD_LIBRARY_PATH is for runtime library linking.

export LIBRARY_PATH=/path/to/libs
窝囊感情。 2024-11-04 04:22:41

我使用的是 Ubuntu14.04 和 gcc。

gcc 将 C_INCLUDE_PATH 添加到搜索目录列表中。
您可以使用 -v 选项来查看 gcc 实际搜索的位置。
INCLUDE_PATH 对我不起作用。)

因此,您可以将以下内容添加到.bashrc

export C_INCLUDE_PATH=/Users/Henry/coding_stuff/c/include/mylib

我找到了官方文档: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:

export C_INCLUDE_PATH=/Users/Henry/coding_stuff/c/include/mylib

I found the official documentation: https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文