microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.28k stars 6.42k forks source link

[qtbase & poco] Undefined reference to pcre2 with qtbase and poco #41170

Open O-Tom opened 1 month ago

O-Tom commented 1 month ago

Describe the bug My project, based on cmake and vcpkg, compiles an executable that requires the qtbase and gdal ports. A vcpkg.json file is used to manage dependencies, and the whole thing works perfectly under windows with the x64-windows triplet. Under linux, with the x64-linux triplet, link phase fails with undefined symbols related to the pcre2 library. I looked for references to this problem before asking you and it seems to me that it is very similar, if not identical, to the one reported by #25941 Although this one is closed, I'm not sure it's been corrected; I haven't found any changes in the logs that correspond directly to the diagnosis made at the time.

I reproduced this issue with the latest release of vcpkg, i.e. https://github.com/microsoft/vcpkg/releases/tag/2024.08.23

Environment

To Reproduce Create an application that links against gdal and qtbase. Build and link under linux with gcc.

Expected behavior No linker error.

Failure logs

...
-- Found PCRE2: /builds/xxxx/_build_/vcpkg_installed/x64-linux/lib/libpcre2-8.a (found version "10.43") 
-- Found OpenSSL: /builds/xxxx/_build_/vcpkg_installed/x64-linux/lib/libcrypto.a (found version "3.3.1") found components: Crypto 
-- Found OpenSSL: /builds/xxxx/_build_/vcpkg_installed/x64-linux/lib/libcrypto.a (found version "3.3.1") found components: SSL 
-- Found WrapSystemZLIB: TRUE (found version "1.3.1") 
-- Using system ZLIB.
-- Found WrapZLIB: TRUE  
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE  
-- Found WrapSystemDoubleConversion: /builds/xxxx/_build_/vcpkg_installed/x64-linux/share/double-conversion/double-conversionConfig.cmake (found version "3.3.0") 
-- Checking for module 'libb2'
--   Found libb2, version 0.98.1
-- Found WrapSystemPCRE2: optimized;/builds/xxxx/_build_/vcpkg_installed/x64-linux/lib/libpcre2-8.a;debug;/builds/xxxx/_build_/vcpkg_installed/x64-linux/lib/libpcre2-16.a (found version "10.43") 
-- Using system PCRE2.
-- Found WrapPCRE2: TRUE  
...

/usr/bin/ld: ../../../vcpkg_installed/x64-linux/lib/libQt6Core.a(qregularexpression.cpp.o): in function `std::unique_ptr<pcre2_real_jit_stack_16, (anonymous namespace)::PcreJitStackFree>::~unique_ptr()':
qregularexpression.cpp:(.text._ZNSt10unique_ptrI23pcre2_real_jit_stack_16N12_GLOBAL__N_116PcreJitStackFreeEED2Ev+0xd): undefined reference to `pcre2_jit_stack_free_16'
/usr/bin/ld: ../../../vcpkg_installed/x64-linux/lib/libQt6Core.a(qregularexpression.cpp.o): in function `safe_pcre2_match_16(pcre2_real_code_16 const*, unsigned short const*, long long, long long, int, pcre2_real_match_data_16*, pcre2_real_match_context_16*)':
qregularexpression.cpp:(.text._ZL19safe_pcre2_match_16PK18pcre2_real_code_16PKtxxiP24pcre2_real_match_data_16P27pcre2_real_match_context_16+0x2a): undefined reference to `pcre2_match_16'
/usr/bin/ld: qregularexpression.cpp:(.text._ZL19safe_pcre2_match_16PK18pcre2_real_code_16PKtxxiP24pcre2_real_match_data_16P27pcre2_real_match_context_16+0xa4): undefined reference to `pcre2_jit_stack_create_16'
/usr/bin/ld: qregularexpression.cpp:(.text._ZL19safe_pcre2_match_16PK18pcre2_real_code_16PKtxxiP24pcre2_real_match_data_16P27pcre2_real_match_context_16+0xc1): undefined reference to `pcre2_jit_stack_free_16'
/usr/bin/ld: qregularexpression.cpp:(.text._ZL19safe_pcre2_match_16PK18pcre2_real_code_16PKtxxiP24pcre2_real_match_data_16P27pcre2_real_match_context_16+0xec): undefined reference to `pcre2_match_16'
/usr/bin/ld: ../../../vcpkg_installed/x64-linux/lib/libQt6Core.a(qregularexpression.cpp.o): in function `QRegularExpressionPrivate::getPatternInfo()':
qregularexpression.cpp:(.text._ZN25QRegularExpressionPrivate14getPatternInfoEv+0x1c): undefined reference to `pcre2_pattern_info_16'
/usr/bin/ld: qregularexpression.cpp:(.text._ZN25QRegularExpressionPrivate14getPatternInfoEv+0x2d): undefined reference to `pcre2_pattern_info_16'
/usr/bin/ld: qregularexpression.cpp:(.text._ZN25QRegularExpressionPrivate14getPatternInfoEv+0x52): undefined reference to `pcre2_pattern_info_16'
/usr/bin/ld: qregularexpression.cpp:(.text._ZN25QRegularExpressionPrivate14getPatternInfoEv+0x71): undefined reference to `pcre2_config_16'
/usr/bin/ld: ../../../vcpkg_installed/x64-linux/lib/libQt6Core.a(qregularexpression.cpp.o): in function `QRegularExpression::~QRegularExpression()':
qregularexpression.cpp:(.text._ZN18QRegularExpressionD2Ev+0x1c): undefined reference to `pcre2_code_free_16'
/usr/bin/ld: ../../../vcpkg_installed/x64-linux/lib/libQt6Core.a(qregularexpression.cpp.o): in function `QExplicitlySharedDataPointer<QRegularExpressionPrivate>::~QExplicitlySharedDataPointer()':

Additional context No.

MonicaLiu0311 commented 1 month ago

Could you please provide a simple repro project(include vcpkg.json).

O-Tom commented 1 month ago

Hi,

Attached is a minimal project reproducing the problem with build commands for x64-linux (which fails) and x64-windows (which works). While building this project, I realized that the conflict was between the poco port and the qtbase port and was not related to the gdal port after all. If the symptoms are similar, it's NOT the same problem as the one identified by #25941. I'll correct the title accordingly.

pcre2_issue.zip pcre2_issue.build.log

dg0yt commented 1 month ago

I fixed gdal upstream. But similar fixes should be applied to poco and qt: Rename the PCRE2_LIBARY cache variable to indicate the chosen implementation (8/16/32).

O-Tom commented 1 month ago

Hi,

In the meantime, I've set up a github project around the minimal case: https://github.com/O-Tom/vcpkg_issue_41170 I've created an automatic build that reproduces the problem. Testing different ways around it, I've noticed that forcing a search for pcre2 BEFORE Qt6 fixes the link:

image

I'll use this workaround for now.

dg0yt commented 1 month ago

Testing different ways around it, I've noticed that forcing a search for pcre2 BEFORE Qt6 fixes the link

This isn't a proper fix. One package will get the wrong lib. It might just be hidden by other circumstances.

github-actions[bot] commented 3 weeks ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

O-Tom commented 2 weeks ago

Hi, I see the title has been updated; I think we can also remove the “requires:repro” label ?

MonicaLiu0311 commented 2 weeks ago

The error was reproduced on x64-linux: Image

smac89 commented 3 days ago

It seems related to this: https://github.com/pocoproject/poco/issues/4598

How can one resolve this issue?

dg0yt commented 2 days ago

https://github.com/microsoft/vcpkg/issues/41170#issuecomment-2378365112