Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a directory to C header include path?

Tags:

c

macos

I am having trouble installing a dependency for a program that itself depends on pcre.h. I have this installed to /opt/local/include, but the C compiler does not see it and thus gives me:

error: pcre.h: No such file or directory

I have confirmed this by writing a hello world program that tries to include it:

#include <pcre.h>
#include <stdio.h>

int main(void)
{
    printf("hello, world\n");
    return 0;
}

This also gives the error unless I specify the path as </opt/local/include/pcre.h>.

I would like the C compiler to find this by default but I do not know where this is configured. Tab completion hasn't revealed any HEADER_PATH environment variables and I cannot find anything like it that isn't specific to XCode. I am, however, using Mac OSX Snow Leopard on the off chance that makes a difference.

like image 790
wdkrnls Avatar asked Jan 28 '11 06:01

wdkrnls


People also ask

What is an include path in C?

For include files that are specified as #include "path-spec" , directory search begins in the directory of the parent file and then proceeds through the directories of any grandparent files. That is, the search begins relative to the directory that contains the source file that's being processed.

Can you use include in a header file?

You make the declarations in a header file, then use the #include directive in every . cpp file or other header file that requires that declaration. The #include directive inserts a copy of the header file directly into the . cpp file prior to compilation.

HOW include all header files in C?

In C language, header files contain the set of predefined standard library functions. You request to use a header file in your program by including it with the C preprocessing directive “#include”. All the header file have a '. h' an extension.

Where is the header file path?

Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.


1 Answers

Use -I /opt/local/include on the command line or C_INCLUDE_PATH=/opt/local/include in the environment.

like image 116
R.. GitHub STOP HELPING ICE Avatar answered Oct 01 '22 10:10

R.. GitHub STOP HELPING ICE