Issue
need to include pcre2 static library in my CMake project.
- I've built last version of pcre2 from official sources and got libpcre2-32.a (I need 32-bit char width libray)
- Put it in my project folder, with its header pcre2.h
- 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.
- 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()
)?
Answered By - nullptr Answer Checked By - Katrina (WPSolving Volunteer)