PHP Windows扩展config.w32链接问题:raylib库GLFW符号未解析
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:
1. Link Required Windows System Libraries
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 likeChoosePixelFormatandCreateBitmapopengl32.lib: Provides OpenGL context supportuser32.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_librariesline 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_LIBSwas 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

