12

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.

wdkrnls
  • 4,206
  • 4
  • 33
  • 54

2 Answers2

26

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

R.. GitHub STOP HELPING ICE
  • 201,833
  • 32
  • 354
  • 689
5

Use the pcre-config utility to get the right flags:

$ pcre-config --libs --cflags
-L/opt/local/lib -lpcre
-I/opt/local/include

If you're compiling via the command line,

$ gcc -Wall -g `pcre-config --libs --cflags` main.c
a paid nerd
  • 29,751
  • 30
  • 126
  • 170