开发者

Compiling error C++ - undefined references using PCRE library

I'm having problems compiling a code to test if the PCRE library is installed correctly.

#include <string> 
#include <iostream> 
#include <pcre.h> 



int main (int argc, char *argv[]) 

{ 
    const char *error; 
    int   erroffset; 
    pcre *re; 
    int   rc; 
    int   i; 
    int   ovector[100]; 

    char *regex = "From:([^@]+)@([^\r]+)"; 
    char str[]  = "From:regular.expressions@example.com\r\n"\ 
                  "From:exddd@43434.com\r\n"\ 
                  "From:7853456@exgem.com\r\n"; 

    re = pcre_compile (regex,          /* the pattern */ 
                       PCRE_MULTILINE, 
                       &error,         /* for error message */ 
                       &erroffset,     /* for error offset */ 
                       0);             /* use default character tables */ 
    if (!re) 
    { 
        printf("pcre_compile failed (offset: %d), %s\n", erroffset, error); 
        return -1; 
    } 

    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("%2d: %.*s\n", i, ovector[2*i+1] - ovector[2*i], str + ovector[2*i]); 
        } 
        offset = ovector[1]; 
    } 
    return 1; 
} 

The error returned is:

[Linker error] undefined reference to `_imp__pcre_compile' 

[Linker error] undefined reference to `_imp__pcre_exec' 

I'开发者_开发百科m pretty sure I'm doing something stupid.

Currently using the IDE Dev-C++ , installed the package using the Dev Package manager.

This is the DevPak package installer: http://www.mediafire.com/?zb3wc6q07sddsac i used to install the library (pcre-6.4.1)

I want some guidance that would lead me to installing this library corretly (So I can work with regular expressions).

If not, I would love a reference to a c++ library to support regular expressions easy to install on this Dev-C++ or CodeBlocks.

Thanks for your help !

EDIT: Thanks for your help, solved this by checking this thread How do I get PCRE to work with C++?

and dumb coders responses in both threads.


Are you having name mangling issues? Does pcre.h have anything like this in it?

extern "C" {
   // declarations of c functions for c++
 }

If not wrap your #include with that and it will inform C++ it's calling C functions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜