如何让cc查看头文件的/ usr / local / include

时间:2022-08-01 15:02:33

I encountered this problem while installing some python modules in which had dependencies on their own C libraries. The problem is, cc is not looking into /usr/local/include at all for header files. I made it work for one of those (thinking it was a problem of the modules) by adding /usr/local/include as one of the external include directories.

我在安装一些python模块时遇到了这个问题,其中有一些依赖于它们自己的C库的模块。问题是,cc并没有考虑头文件的/ usr / local / include。我通过添加/ usr / local / include作为外部包含目录之一,使其适用于其中一个(认为这是模块的问题)。

Then, to test, I wrote a simple hello.c file and added #include "fftw3.h" / #include <fftw3.h> and it failed to compile if I didn't explicitly add -I/usr/local/include.

然后,为了测试,我编写了一个简单的hello.c文件,并添加了#include“fftw3.h”/ #include ,如果我没有明确添加-I / usr / local / include,则无法编译。

I added a line in my ~/.bash_profile to export the include the directory path to $PATH; didn't work either.

我在〜/ .bash_profile中添加了一行来导出包含$ PATH的目录路径;也没用。

So, my question is, how do I make cc look for header files in /usr/local/include (or, for that matter, in any custom directory) always without passing -I flag?

所以,我的问题是,如何让cc在/ usr / local / include(或者,就此而言,在任何自定义目录中)查找头文件总是不传递-I标志?

FYI: I'm using macbook pro running OSX 10.11

仅供参考:我正在使用运行OSX 10.11的macbook pro

2 个解决方案

#1


2  

If you are using GCC then you have three environment variables you can use:

如果您正在使用GCC,那么您可以使用三个环境变量:

  • CPATH
  • CPATH
  • C_INCLUDE_PATH
  • C_INCLUDE_PATH
  • CPLUS_INCLUDE_PATH
  • CPLUS_INCLUDE_PATH

Take a look here.

看看这里。

EDIT: since you specified you are working with OS X (hence Clang), they should be supported too, take a look ad the end here. It's not uncommon to have Clang mimic GCC specs just to help in compatibility.

编辑:既然你指定你正在使用OS X(因此Clang),他们也应该得到支持,看看广告到底在这里。让Clang模仿GCC规范只是为了帮助兼容性并不罕见。

#2


0  

I think you should invest some time in understanding build systems. For example gnu make. Here, look at this:

我认为你应该花一些时间来理解构建系统。例如gnu make。在这里,看看这个:

CC = gcc
CFLAGS = -Wall
DEPS = primes.h
OBJ = go.o primes.o

%.o: %.c $(DEPS)
        $(CC) $(CFLAGS) -c -o $@ $<

go: $(OBJ)
        gcc $(CFLAGS) -o $@ $^

This gives you:

这给你:

  • The freedom to add any compiler you want. In your case that would be cc, in this example it is gcc.
  • 可以*添加任何所需的编译器。在你的情况下,这将是cc,在这个例子中它是gcc。
  • use cflags to control to adjust the compiler - in the example -Wall will turn on the warnings
  • 使用cflags来控制调整编译器 - 在示例中-Wall将打开警告
  • make your build work reproducible
  • 使您的构建工作可重复
  • prepare recipe with complex rules for compilation as your application grow
  • 随着应用程序的增长,准备具有复杂规则的配方进行编译

More information is available here.

更多信息请点击这里。

#1


2  

If you are using GCC then you have three environment variables you can use:

如果您正在使用GCC,那么您可以使用三个环境变量:

  • CPATH
  • CPATH
  • C_INCLUDE_PATH
  • C_INCLUDE_PATH
  • CPLUS_INCLUDE_PATH
  • CPLUS_INCLUDE_PATH

Take a look here.

看看这里。

EDIT: since you specified you are working with OS X (hence Clang), they should be supported too, take a look ad the end here. It's not uncommon to have Clang mimic GCC specs just to help in compatibility.

编辑:既然你指定你正在使用OS X(因此Clang),他们也应该得到支持,看看广告到底在这里。让Clang模仿GCC规范只是为了帮助兼容性并不罕见。

#2


0  

I think you should invest some time in understanding build systems. For example gnu make. Here, look at this:

我认为你应该花一些时间来理解构建系统。例如gnu make。在这里,看看这个:

CC = gcc
CFLAGS = -Wall
DEPS = primes.h
OBJ = go.o primes.o

%.o: %.c $(DEPS)
        $(CC) $(CFLAGS) -c -o $@ $<

go: $(OBJ)
        gcc $(CFLAGS) -o $@ $^

This gives you:

这给你:

  • The freedom to add any compiler you want. In your case that would be cc, in this example it is gcc.
  • 可以*添加任何所需的编译器。在你的情况下,这将是cc,在这个例子中它是gcc。
  • use cflags to control to adjust the compiler - in the example -Wall will turn on the warnings
  • 使用cflags来控制调整编译器 - 在示例中-Wall将打开警告
  • make your build work reproducible
  • 使您的构建工作可重复
  • prepare recipe with complex rules for compilation as your application grow
  • 随着应用程序的增长,准备具有复杂规则的配方进行编译

More information is available here.

更多信息请点击这里。