编译错误C ++ - 使用PCRE库的未定义引用 [英] Compiling error C++ - undefined references using PCRE library

查看:2640
本文介绍了编译错误C ++ - 使用PCRE库的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编译代码以测试PCRE库是否正确安装时遇到问题。

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; 
} 

返回的错误是

[Linker error] undefined reference to `_imp__pcre_compile' 

[Linker error] undefined reference to `_imp__pcre_exec' 

我确定我做的事很蠢。

目前使用IDE Dev-C ++,使用开发包管理器安装包。

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

这是DevPak包安装程序: http://www.mediafire.com/?zb3wc6q07sddsac 我用于安装库(pcre-6.4 .1)

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).

如果没有,我会喜欢对c ++库的引用,以支持在这个Dev-C ++或CodeBlocks上容易安装的正则表达式。

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

您的帮助!

编辑
感谢您的帮助,通过检查此线程如何让PCRE使用C ++?

和两个线程中的哑编码器响应。

and dumb coders responses in both threads.

推荐答案

pcre.h中有这样的东西吗?

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

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

如果不包装你的#include,调用C函数

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

这篇关于编译错误C ++ - 使用PCRE库的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆