使用GLEW创建窗口遇未解析外部符号glewExperimental链接错误求助
glewExperimental in GLEW + GLFW Setup Hey there, let's work through that unresolved external symbol error for glewExperimental you're facing. Even though you've compiled the library and confirmed linking, there are a few common gotchas that might be causing this. Here's what to check:
1. Match Library Build Type to Your Project
Linker errors often pop up when there's a mismatch between your project's build configuration and the GLEW library you're linking:
- If you're building in Debug mode, make sure you're linking the Debug version of GLEW (usually named
glew32d.libon Windows). Release mode usesglew32.lib. Mixing these will lead to missing symbols. - Double-check 32-bit vs 64-bit compatibility: Your project's target architecture (x86/x64) must match the architecture of the GLEW library you compiled or downloaded.
2. Define the Correct Linkage Macro
GLEW behaves differently depending on whether you're using static or dynamic linking, and you need to define the right macro before including the header:
- For static linking, add
#define GLEW_STATICbefore including<GL/glew.h>in your code:
If you skip this, the compiler will look for dynamic library export symbols, which won't exist in your static library.#define GLEW_STATIC #include <GL/glew.h> #include <GLFW/glfw3.h> - For dynamic linking, ensure
GLEW_SHAREDis defined (this is often the default, but it's worth verifying).
3. Verify Your Custom GLEW Build Settings
Since you compiled GLEW yourself, double-check these build options:
- If using CMake, confirm whether
BUILD_SHARED_LIBSwas set toON(dynamic) orOFF(static) — this must match your project's linkage choice. - Make sure you didn't disable any critical features during compilation. Stick to the default build settings unless you have a specific reason to change them, as custom flags can accidentally exclude symbols like
glewExperimental.
4. Double-Check Linker Inputs
- In MSVC: Right-click your project → Properties → Linker → Input → Additional Dependencies. Ensure the correct GLEW library name is listed, and that the library's directory is added to Linker → General → Additional Library Directories.
- In MinGW/GCC: When compiling, make sure you're passing the correct linker flag (e.g.,
-lglew32dfor Debug static,-lglew32for Release static). Also, ensure the library path is included with-L/path/to/glew/libs.
Quick Check of Your Code Snippet
Looking at your code, the issue is unlikely to be in the logic itself — it's almost certainly a linkage/build mismatch. Just to be thorough, ensure that glfwMakeContextCurrent(handle) is called before any GLEW calls (which you are doing correctly), since GLEW needs a valid OpenGL context to initialize.
内容的提问来源于stack exchange,提问作者sakura

