C++ pcre2_compile获得不完整的类型

c++ pcre2_compile gets incomplete type

本文关键字:类型 pcre2 compile C++      更新时间:2023-10-16

[g++4.8.2, pcre2-10.31, linux] [C++ ~newbie]我正在尝试学习如何从c ++程序使用对pcre2的一些简单调用。

#include <string>
#define PCRE2_CODE_UNIT_WIDTH 8
#include "pcre2.h"
int main()
{
  std::string xpattern = "(\+|-)?[[:digit:]]+";
  int errorcode;
  PCRE2_SIZE *erroroffset = NULL;
  pcre2_code *code = pcre2_compile((const unsigned char *)xpattern.c_str(), PCRE2_ZERO_TERMINATED, 0, &errorcode, erroroffset, NULL); 
}
g++ -I/scratch_b/qa/tmp/pcre/include -g -Wall -o simple simpleregex2.cpp
simpleregex2.cpp: In function ‘int main()’:
simpleregex2.cpp:9:15: warning: unused variable ‘code’ [-Wunused-variable]
   pcre2_code *code = pcre2_compile((const unsigned char *)xpattern.c_str(), PCRE2_ZERO_TERMINATED, 0, &errorcode, erroroffset, NULL); 
               ^
simpleregex2.cpp:9: error: undefined reference to 'pcre2_compile_8'
collect2: error: ld returned 1 exit status

谢谢,我解决了指针问题,仍然得到"未定义的引用"...?

知道了,谢谢大家: g++ -I/scratch_b/qa/tmp/pcre//include -g -Wall simpleregex2.cpp -o simple -wl,-rpath,/scratch_b/qa/tmp/pcre//lib -L/scratch_b/qa/tmp/pcre//lib -lpcre2-8