Cygwin/X X11转发树莓派至Windows时C程序运行挂起求助
Let's break down why your C program is hanging after outputting init_SDL in your Cygwin X11 forwarding setup. Here are actionable steps to diagnose and fix the issue:
Force SDL to use the X11 backend
By default, SDL in Cygwin might try to use the native Windows display backend instead of X11, which conflicts with your forwarding setup. Before running your program, set this environment variable:export SDL_VIDEODRIVER=x11This ensures SDL talks directly to your X11 server instead of trying to access Windows' display system, which could be causing the hang.
Validate GLX support in your X11 setup
Your program attempts to initialize OpenGL next, so if your X11 forwarding doesn't have GLX enabled, SDL might hang waiting for a GL context. First, runglxinfoin your Cygwin terminal—if this command hangs or errors out, you're missing GLX support.
Install the required Cygwin packages to fix this:apt-cyg install mesa-libGL-devel mesa-libGLU-devel xorg-x11-develAlso, make sure your X server (running on Windows) was started with GLX enabled—most modern Cygwin X servers include this by default, but double-check the launch parameters for
-glxif you customized them.Add SDL error checking to your code
Theinit_SDLmessage is printed, but SDL might be hitting an error that's not being reported. Modify yourdraw.ccode to capture SDL errors right after initialization:// Inside your init_SDL function if (SDL_Init(SDL_INIT_VIDEO) != 0) { fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } // Also check window creation if that's part of init_SDL SDL_Window* window = SDL_CreateWindow(...); if (!window) { fprintf(stderr, "SDL_CreateWindow failed: %s\n", SDL_GetError()); SDL_Quit(); exit(EXIT_FAILURE); }This will tell you exactly where SDL is getting stuck—whether it's initializing the video subsystem or creating the window.
Verify all dependencies are installed
Missing SDL or OpenGL libraries can cause silent hangs instead of explicit errors. Ensure you have all required packages installed for your program:# For SDL2 (adjust to SDL1 if your program uses it) apt-cyg install libsdl2-devel libsdl2-image-develTest with a minimal SDL X11 program
Rule out whether the issue is with your environment or your specific program. Create a small test program like this:#include <SDL2/SDL.h> int main() { if (SDL_Init(SDL_INIT_VIDEO) != 0) { fprintf(stderr, "SDL_Init error: %s\n", SDL_GetError()); return 1; } SDL_Window* win = SDL_CreateWindow( "SDL X11 Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL ); if (!win) { fprintf(stderr, "Window creation error: %s\n", SDL_GetError()); SDL_Quit(); return 1; } printf("SDL window created successfully—no hang!\n"); SDL_Delay(2000); SDL_DestroyWindow(win); SDL_Quit(); return 0; }Compile and run it with:
gcc sdl_test.c -o sdl_test `sdl2-config --cflags --libs` ./sdl_testIf this test program hangs too, focus on fixing your X11/SDL environment. If it runs, the problem is in your program's OpenGL or subsequent initialization steps (like
init_gl).
内容的提问来源于stack exchange,提问作者user2559392

