dimanche 16 août 2020

PCRE in C++ on windows and Visual Studio 2017 getting LNK2019

I recently had to make some code changes in a C++11 project a function used PCRE only when running on linux. The code changes involved using PRCE while running on windows (as part of dev process) and some linkage problems showed up.

The project is aimed to use the static pcre8.lib, with PCRE_STATIC set in preprocessor definitions. The project is set to debug configuration and platform x64. I've seen some solutions to similar issues suggesting to change BUILD_SHARED_LIBS to "off" but I can't find where to do it, and I'm not 100% sure this is the cause of the problem.

The lib is taken from the package installed in the project via NuGet. I suspect the difference in behavior may be occuring because so far we've only used the .a and header files of the linux-build PCRE package. The windows NuGet one has 2 headers in the include directory, while the linux-built one created 6. But I'm a beginner in C++ so I may be wrong.

The errors I get when I build the project are:

Parser.lib(HandlingFunction.obj) error LNK2019: unresolved external symbol "public: __cdecl pcrecpp::RE::~RE(void)" (??1RE@pcrecpp@@QEAA@XZ) referenced in function "public: void * __cdecl pcrecpp::RE::`scalar deleting destructor'(unsigned int)" (??_GRE@pcrecpp@@QEAAPEAXI@Z)
Parser.lib(HandlingFunction.obj) : error LNK2019: unresolved external symbol "private: void __cdecl pcrecpp::RE::Init(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class pcrecpp::RE_Options const *)" (?Init@RE@pcrecpp@@AEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBVRE_Options@2@@Z) referenced in function "public: __cdecl pcrecpp::RE::RE(class pcrecpp::RE const &)" (??0RE@pcrecpp@@QEAA@AEBV01@@Z)

What can I do, other than #ifdef to not use PCRE on windows (an ugly solution I try to only use if nothing else will work)?

Thanks.

Aucun commentaire:

Enregistrer un commentaire