You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code配置Poco库CMakeLists.txt遇兼容及PCRE2查找问题求助

问题:Windows 10下VS Code+g+++vcpkg配置Poco库的CMake错误

环境信息

  • Windows 10 + VS Code
  • 编译器:g++(来自MSYS2 Mingw64)
  • vcpkg安装路径:C:/src/vcpkg
  • 已通过vcpkg安装Poco、PCRE2等库

初始CMakeLists.txt配置

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_TOOLCHAIN_FILE "C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake"
    CACHE STRING "Vcpkg toolchain file")

# Add the directory where your packages are installed
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};C:/src/vcpkg/installed/x86-windows")

set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)

# Set the path to the Poco package configuration files
# set(Poco_DIR "C:/src/vcpkg/")

find_package(poco REQUIRED COMPONENTS Foundation JSON) 

阶段1:架构不兼容错误

调整配置后出现如下错误:

[cmake] Could not find a configuration file for package "poco" that is compatible
[cmake] with requested version "".
[cmake]
[cmake] The following configuration files were considered but not accepted:
[cmake]
[cmake] C:/src/vcpkg/installed/x86-windows/share/poco/pocoConfig.cmake, version: 1.12.4 (32bit)

尝试设置set(CMAKE_GENERATOR_PLATFORM "x86")无效,随后切换安装x64版本的Poco库。

阶段2:PCRE2库找不到错误

切换到x64库后,出现新的CMake错误:

[cmake] -- Found ZLIB: C:/src/vcpkg/installed/x64-windows/lib/zlib.lib (found version "1.2.13") 
[cmake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake]   Could NOT find PCRE2 (missing: PCRE2_LIBRARY)
[cmake] Call Stack (most recent call first):
[cmake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/FindPCRE2.cmake:94 (find_package_handle_standard_args)
[cmake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/PocoFoundationConfig.cmake:5 (find_dependency)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/PocoConfig.cmake:35 (find_package)
[cmake]   CMakeLists.txt:19 (find_package)

已确认PCRE2库存在于C:\src\vcpkg\installed\x64-windows\lib路径下:

-a----        30/05/2023     14:43          20424 pcre2-16.lib
-a----        30/05/2023     14:43          20424 pcre2-32.lib
-a----        30/05/2023     14:42          19974 pcre2-8.lib
-a----        30/05/2023     14:43           2362 pcre2-posix.lib

调整配置(使用Ninja生成器,指定Mingw64编译器)后,错误依旧:

[main] Configuring project: helloworld 
[proc] Executing command: "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE:STRING=c:/src/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=C:\msys64\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=C:\msys64\mingw64\bin\g++.exe "-SC:/Users/phild/Documents/C++ Projects/helloworld" "-Bc:/Users/phild/Documents/C++ Projects/helloworld/build" -G Ninja
[cmake] Not searching for unused variables given on the command line.
[cmake] -- The C compiler identification is GNU 12.2.0
[cmake] -- The CXX compiler identification is GNU 12.2.0
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Found ZLIB: optimized;C:/src/vcpkg/installed/x64-windows/lib/zlib.lib;debug;C:/src/vcpkg/installed/x64-windows/debug/lib/zlibd.lib (found version "1.2.13") 
[cmake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
[cmake]   Could NOT find PCRE2 (missing: PCRE2_LIBRARY)
[cmake] Call Stack (most recent call first):
[cmake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/FindPCRE2.cmake:94 (find_package_handle_standard_args)
[cmake]   C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake:853 (_find_package)
[cmake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/PocoFoundationConfig.cmake:5 (find_dependency)
[cmake]   C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake:853 (_find_package)
[cmake]   C:/src/vcpkg/installed/x64-windows/share/poco/PocoConfig.cmake:35 (find_package)
[cmake]   C:/src/vcpkg/scripts/buildsystems/vcpkg.cmake:853 (_find_package)
[cmake]   CMakeLists.txt:13 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!

请求解决

请指出问题原因并提供解决方案。

内容的提问来源于stack exchange,提问作者Phil Davies

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 14:54:58