Fedora系统下CodeBlocks配置GLFW 3.2.1遇阻,寻求帮助
Hey there! Let's break down how to verify your GLFW installation and get it properly configured in CodeBlocks. First, let's confirm your initial build steps are correct, then tackle the path setup.
Step 1: Verify Your GLFW Installation Was Successful
Your commands cmake -DBUILD_SHARED_LIBS=ON . and sudo make install are actually correct for building and installing the shared GLFW library. Let's double-check the files were installed to the right places:
Open a terminal and run these commands to confirm:
# Check if GLFW headers exist ls /usr/local/include/GLFW/ # Check if GLFW shared library exists ls /usr/local/lib/libglfw*
You should see files like glfw3.h in the include directory, and libglfw.so (plus symlinks like libglfw.so.3/libglfw.so.3.2) in the lib directory. If these are missing, re-run your build steps—make sure you ran cmake from the root of the extracted GLFW folder, and that make install completed without errors.
If the files exist but CodeBlocks still can't find them, run this to update the system's dynamic library cache:
sudo ldconfig
Step 2: Configure CodeBlocks to Use GLFW
You can set this up for a single project (recommended for testing first) or globally (so all new projects use GLFW by default).
Option A: Single Project Configuration
- Open your CodeBlocks project, then right-click the project name in the left sidebar and select Build options.
- In the window that pops up, select your project (not the target under it) and go to the Search directories tab:
- Under Compiler: Click Add, enter
/usr/local/include, and check the Recursive box (this lets CodeBlocks find the nestedGLFWsubdirectory automatically). - Under Linker: Click Add, enter
/usr/local/lib.
- Under Compiler: Click Add, enter
- Switch to the Linker settings tab:
- In the Other linker options field, add these flags:
The-lglfw -lGL-lglfwlinks the GLFW library, and-lGLlinks the system OpenGL library (required for GLFW to work).
- In the Other linker options field, add these flags:
Option B: Global Configuration (All New Projects)
- Open CodeBlocks, go to Settings > Compiler.
- Go to the Search directories tab:
- Under Compiler: Add
/usr/local/include. - Under Linker: Add
/usr/local/lib.
- Under Compiler: Add
- Switch to the Linker settings tab, and add
-lglfw -lGLto the Other linker options field.
Step 3: Test the Setup
Create a simple test program to confirm everything works:
#include <GLFW/glfw3.h> int main() { if (!glfwInit()) { return -1; } glfwTerminate(); return 0; }
Build and run this—if it compiles without errors, your GLFW configuration is working!
内容的提问来源于stack exchange,提问作者Daniel Gimenez

