c++ - MS VC++ 9 pcrecpp.lib linking error -
just built pcre-8.34
ms vc++ under windows x86, copied libs (pcrecpp.lib) , headers (pcrecpp.h, pcrecpparg.h, pcre_stringpiece.h) locations , wanted test simple code (that works under gnu linux c++) i'm getting linking errors:
#define pcre_static 1 #include <pcrecpp.h> #include <iostream> #pragma comment(lib,"pcrecpp.lib") using namespace std; int main(void) { pcrecpp::re regex("(hello)"); std::string strbase = "hello hello hello"; pcrecpp::stringpiece input(strbase); std::string match; int count = 0; while (regex.findandconsume(&input, &match)) { count++; std::cout << count << " " << match << std::endl; } }
building output:
c:\documents , settings\administrator\desktop\coding\pcre>cl.exe /md /ehsc /o2 pc.cpp microsoft (r) 32-bit c/c++ optimizing compiler version 15.00.21022.08 80x86 copyright (c) microsoft corporation. rights reserved.
pc.cpp microsoft (r) incremental linker version 9.00.21022.08 copyright (c) microsoft corporation. rights reserved.
/out:pc.exe pc.obj pcrecpp.lib(pcrecpp.obj) : error lnk2019: unresolved external symbol _pcre_compi le referenced in function "private: struct real_pcre * __thiscall pcrecpp::re::c ompile(enum pcrecpp::re::anchor)" (?compile@re@pcrecpp@@aaepaureal_pcre@@w4ancho r@12@@z) pcrecpp.lib(pcrecpp.obj) : error lnk2019: unresolved external symbol _pcre_confi g referenced in function "int __cdecl pcrecpp::newlinemode(int)" (?newlinemode@p crecpp@@yahh@z) pcrecpp.lib(pcrecpp.obj) : error lnk2019: unresolved external symbol _pcre_exec referenced in function "private: int __thiscall pcrecpp::re::trymatch(class pcre cpp::stringpiece const &,int,enum pcrecpp::re::anchor,bool,int *,int)const " (?t rymatch@re@pcrecpp@@abehabvstringpiece@2@hw4anchor@12@_npahh@z) pcrecpp.lib(pcrecpp.obj) : error lnk2019: unresolved external symbol _pcre_fulli nfo referenced in function "public: int __thiscall pcrecpp::re::numberofcapturin ggroups(void)const " (?numberofcapturinggroups@re@pcrecpp@@qbehxz) pcrecpp.lib(pcrecpp.obj) : error lnk2019: unresolved external symbol _pcre_free referenced in function "private: void __thiscall pcrecpp::re::cleanup(void)" (?c leanup@re@pcrecpp@@aaexxz) pc.exe : fatal error lnk1120: 5 unresolved externals
any idea doing wrong? tried under vc++ 10, same errors. should include <pcre.h>
, #pragma comment(lib,"pcre.lib")
because if link occurs without error seem strange use c header , library in c++ code?
update:
i did this, , works, problem is: ok c++?
#define pcre_static 1 #include <pcrecpp.h> #include <iostream> #pragma comment(lib,"pcrecpp.lib") #pragma comment(lib,"pcre.lib") using namespace std; int main(void) { pcrecpp::re regex("(hello)"); std::string strbase = "hello hello hello"; pcrecpp::stringpiece input(strbase); std::string match; int count = 0; while (regex.findandconsume(&input, &match)) { count++; std::cout << count << " " << match << std::endl; } }
output:
c:\documents , settings\administrator\coding\pcre>cl.exe /o2 /md /ehsc pcc.cpp /link /subsystem:console kernel32.lib user32.lib wininet.lib pcre.lib microsoft (r) 32-bit c/c++ optimizing compiler version 15.00.21022.08 80x86 copyright (c) microsoft corporation. rights reserved.
pc.cpp microsoft (r) incremental linker version 9.00.21022.08 copyright (c) microsoft corporation. rights reserved.
/out:pc.exe /subsystem:console kernel32.lib user32.lib wininet.lib pcre.lib get_all_proc.obj
you need link against "pcre.lib". if have @ "pcrecpp.h" source code see includes "pcre.h" uses "c part" of library.
Comments
Post a Comment