c++cmakestatic-librariespcre2

pcre2: include a static library in c++ CMake project


need to include pcre2 static library in my CMake project.

  1. I've built last version of pcre2 from official sources and got libpcre2-32.a (I need 32-bit char width libray)
  2. Put it in my project folder, with its header pcre2.h
  3. Have added this library to CMakeLists.txt:
...
include_directories(SupportFiles/OSLinux/pcre2)
...
add_library(libpcre2 STATIC IMPORTED GLOBAL)
find_library(libpcre2_path NAMES libpcre2-32.a HINTS ${CMAKE_SOURCE_DIR}/SupportFiles/OSLinux/pcre2/ REQUIRED NO_CMAKE_SYSTEM_PATH)
message(">>>>>> libpcre2_path = ${libpcre2_path}")
set_property(TARGET libpcre2 PROPERTY IMPORTED_LOCATION ${libpcre2_path})
target_link_libraries(appservicehttpmodule PRIVATE libpcre2)
...

Library was found in my project and no CMake errors are.

  1. Have added simple pcre2 code in my project
#define PCRE2_CODE_UNIT_WIDTH 32
#include "pcre2.h" 
... 
pcre2_code *pcode = pcre2_compile(...)

get an error :

/usr/bin/ld: CMakeFiles/UnitTest.dir/test.cpp.o: in function `moduleTest_pcre2Presence_Test::TestBody()':
/home/.../GoogleTest/test.cpp:248: undefined reference to `pcre2_compile_32'

What is wrong? Why this lib is not linked?

Thanks in advance.


Solution

  • (I don't have enough reputation to leave comments :( )

    The linker error seems to be from a separate executable (a unit test). Does it have libpcre2 added as a dependency (using target_link_libraries())?