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

PHP Windows扩展config.w32链接问题:raylib库GLFW符号未解析

Fixing LNK2019 Errors When Integrating Raylib into a PHP Extension on Windows

Hey there, I’ve dealt with nearly identical linker headaches when getting raylib working in Windows-based C projects—including PHP extensions—so let’s break down exactly how to fix those __imp_ChoosePixelFormat and __imp_CreateBitmap LNK2019 errors.

These unresolved symbols aren’t actually issues with raylib itself; they’re missing Windows system libraries that raylib (via GLFW) depends on to handle OpenGL and GDI operations. Here’s what you need to do:

The functions throwing errors belong to Windows’ GDI and OpenGL subsystems. You need to explicitly add these libraries to your linker inputs:

  • gdi32.lib: Handles graphics device interface functions like ChoosePixelFormat and CreateBitmap
  • opengl32.lib: Provides OpenGL context support
  • user32.lib: Manages windowing and user input

How to add them:

  • Visual Studio: Right-click your PHP extension project → Properties → Configuration Properties → Linker → Input → Additional Dependencies. Add raylib.lib;gdi32.lib;opengl32.lib;user32.lib; to the list.
  • CMake: If you’re using CMake to build your extension, update your target_link_libraries line to include these system libs:
    target_link_libraries(your_php_extension_name PRIVATE
        raylib
        gdi32
        opengl32
        user32
    )
    

2. Verify Raylib’s Compatibility with Your Build Setup

Mismatched build configurations are another common culprit:

  • Architecture: Make sure your raylib library (x86 vs x64) matches exactly with your PHP extension’s target architecture. PHP on Windows often ships as x86 by default, so don’t use a 64-bit raylib build by mistake.
  • Runtime Mode: Debug builds of your extension need a Debug-compiled raylib, and Release builds need a Release raylib. Mixing these will cause missing symbols.
  • Compiler Version: PHP extensions on Windows are typically built with specific Visual Studio versions (e.g., PHP 8.x uses VS 2019). Ensure you compiled raylib with the same VS version to avoid ABI incompatibilities.

3. Check Raylib’s Build Type

If you compiled raylib yourself:

  • If you’re dynamically linking raylib (using the DLL), ensure BUILD_SHARED_LIBS was enabled in CMake. This generates the correct import library (raylib.lib) that references the DLL’s symbols.
  • If you’re statically linking, confirm raylib was compiled with all dependencies included—sometimes missing compile flags can leave out required GDI/OpenGL symbols.

Quick Troubleshooting Tip

If you’re still stuck, open your raylib.lib in a tool like dumpbin (included with Visual Studio) to check if the missing symbols are present. Run this command in the Developer Command Prompt:

dumpbin /symbols raylib.lib | findstr "__imp_ChoosePixelFormat"

If no results show up, your raylib build is missing these symbols—recompile it with the correct Windows target settings.


内容的提问来源于stack exchange,提问作者Joseph Montanez

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:04:49