In function `main': testpcre.c:(.text+0x93): undefined reference to `pcre_compile' testpcre.c:(.tex

版权声明:感谢阅读,欢迎批评指正。 https://blog.csdn.net/skyejy/article/details/88789129

从昨晚困扰我到现在的问题,终于解决了~~~

先贴源程序

testpcre.c

#include <pcre.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char ** argv)
{
    if (argc != 3)
    {   
        printf("Usage: %s pattern text\n", argv[0]);
        return 1;
    }   
                                      
    const char * pPattern = argv[1];
    const char * pText = argv[2];
    const char * pErrMsg = NULL;
    pcre * pPcre = NULL;
    int nOffset = -1; 
                                      
    if (NULL == (pPcre = pcre_compile(pPattern, 0, &pErrMsg, &nOffset, NULL)))
    {   
        printf("ErrMsg=%s, Offset=%d\n", pErrMsg, nOffset);
        return 1;
    }   
    else
    {   
        if (pcre_exec(pPcre, NULL, pText, strlen(pText), 0, 0, NULL, 0) < 0)
        {   
            printf("%s doesn't match %s\n", pText, pPattern);
        }   
        else
        {   
            printf("%s matches %s\n", pText, pPattern);
        }
    }
}

昨晚已经下载好pcre了

可是一运行还是会报错

查了半天才知道运行的时候要在命令行链接上 :   -lpcre

 gcc -o testpcre testpcre.c -lpcre

然后就可以了!!!

猜你喜欢

转载自blog.csdn.net/skyejy/article/details/88789129