WorkerVMachine
WorkerVMachine

Reputation: 31

How to get a completely static build of pcre2

I'm trying to build pcre2 statically on Windows 10 using cmake. The steps I've taken are:

md C:\ProgramData\ThirdParty\installed\pcre2
md pcre2
curl https://ftp.pcre.org/pub/pcre/pcre2-10.35.tar.gz -o tmp.tar.gz
tar -xf tmp.tar.gz -C pcre2 --strip-components=1
cd pcre2
md build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX="C:\ProgramData\ThirdParty\installed\pcre2" -DBUILD_SHARED_LIBS=OFF -DPCRE2_STATIC=ON -DPCRE2_BUILD_TESTS=OFF -DZLIB_LIBRARY="C:\ProgramData\ThirdParty\installed\zlib\lib\zlibstatic.lib"
cmake --build . --config Release --target install

Despite these settings that should if I understand correctly build a static library I get unresolved external symbol errors when trying to link against pcre2-8.lib, I also include pcre2-posix.lib for good measure.

Using DUMPBIN /SYMBOLS to look at both lib files there are external symbols that I'm guessing point to pcre2-8.dll in the bin directory of the build output.

Is it possible to get pcre2-8.lib to have no external references?

Thanks in advance for your time.

Upvotes: 3

Views: 1670

Answers (1)

user2134488
user2134488

Reputation: 511

It is already static. Just define the macro-name PCRE2_STATIC before #include "pcre2.h" in the project where the library is going to be used.

like this:

#define PCRE2_STATIC
#define PCRE2_CODE_UNIT_WIDTH 8

#include "pcre2.h"

Upvotes: 3

Related Questions