Worked, thanks!

So I'm now using this line: gcc -o -m64 -std=gnu99 -fPIC
-shared -export-dynamic main.c -lm -lpcre

It seems the version 3 number was not needed after all.

I've attached the C code for reference and this is what I use in PL:

   (pipe (native "pcre/" "pcre_match_all" NIL
"From:([\^@]+)@([\^\\.]+)\\.([\^ ]+)"
            (let? R (line T)
               (link R)) ) ) ) )

I noted that ^ needs to be escaped otherwise the regex string won't be
OK on the C side. Are there any other characters which needs the same


("From:regular.exÄ" "regular.exÄpressions"
"example" "com" "" "exddd" "43434" "com"
"" "7853456" "exgem" "com")

On Sun, May 13, 2012 at 12:06 AM, Alexander Burger <> wrote:
> Hi Henrik,
>> Thanks a lot but it seems I can't try it out because apparently I'm
>> not able to create a shared library.
>> I get symbol lookup error: pcre/ undefined symbol:
>> pcre_compile even though my compile lines look like this:
>>  gcc main.c -c -std=gnu99 -fPIC -I/usr/local/include -I/usr/include
>> -L/usr/local/lib -L/usr/lib -lpcre3
>>  gcc -shared -rdynamic -o main.o
>> In the first line I've also tried -lpcre, -llibpcre and -llibpcre3 to no 
>> avail.
> I'm always using a line like:
>   gcc -o <file>.so -m64 -fPIC -shared -export-dynamic <file>.c -lm
> so does this work if you append "-lpcre3"?
> Note (in general, not your problem here, I think) that <file>.so should
> either contain a slash (e.g. like "pcre/" in your previous
> example), or it must be passed as "./" to 'native', because
> otherwise it is searched for in the system libraries (e.g. via
> Cheers,
> - Alex
> --
#include <string.h>
#include <stdio.h>
#include <pcre.h>

 gcc main.c -std=gnu99 -lpcre -o main
 gcc -o -m64 -std=gnu99 -fPIC -shared -export-dynamic main.c -lm -lpcre
 ./main "From:([^@]+)@([^\\.]+)\\.([^ ]+)" "From:regular.exÄ"
 ./main "[0-9]+" "hello777world99yew 8 I8909do23"
 ./main "From:([^ ]+)" "From:hej From:svejs From:apa"
 ./main "From:([a-z]+)" "From:hej From:svejs From:apa"

void pcre_match_all (char *regex, char *str)
    const char *error;
    int   erroffset;
    pcre *re;
    int   rc;
    int   i;
    int   ovector[100];

    re = pcre_compile (regex,          
    if (!re)
        printf("pcre_compile failed (offset: %d), %s\n", erroffset, error);

    unsigned int offset = 0;
    unsigned int len    = strlen(str);
    while (offset < len && (rc = pcre_exec(re, 0, str, len, offset, 0, ovector, sizeof(ovector))) >= 0)
        for(int i = 0; i < rc; ++i)
            printf("%.*s\n", ovector[2*i+1] - ovector[2*i], str + ovector[2*i]);
        offset = ovector[1];

void main (int argc, char *argv[])
	pcre_match_all(argv[1], argv[2]);

Reply via email to