X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Lilja Subject: Re: SDL/OpenGL program fails to link when I want to use wgl-function Date: Mon, 23 Oct 2006 17:07:28 +0200 Lines: 187 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) In-Reply-To: Cc: sdl AT libsdl DOT org X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Eric Lilja wrote: > Hello, I'm using a fully updated cygwin and mingw developement binaries > of SDL (version 1.2.11). Consider the following program: > > //#include > #include > #include > > #include > > static void > display() > { > glClear(GL_COLOR_BUFFER_BIT); > > glBegin(GL_POLYGON); > glVertex2f(-0.5f,-0.5f); > glVertex2f(-0.5f, 0.5f); > glVertex2f( 0.5f, 0.5f); > glVertex2f( 0.5f,-0.5f); > glEnd(); > > SDL_GL_SwapBuffers(); > } > > int > main(int argc, char *argv[]) > { > (void)argc; > (void)argv; > > int retval = SDL_Init(SDL_INIT_VIDEO); > > assert(retval == 0); > > SDL_Surface *surface = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); > > assert(surface != NULL); > > SDL_WM_SetCaption("Simple SDL/OpenGL demo", NULL); > > SDL_Event event; > > //wglGetProcAddress("foo"); > > while (true) > { > while (SDL_PollEvent(&event)) > { > switch (event.type) > { > case SDL_QUIT: > { > SDL_Quit(); > > exit(EXIT_SUCCESS); > } > } > } > > display(); > } > > assert(0); /* Not reached. */ > } > > Makefile I use: > CXX = g++ > CXXFLAGS = -Wall -Wextra -std=c++98 -pedantic -g -O0 -I > ~/SDL-1.2.11/include -c > LDFLAGS = -L ~/SDL-1.2.11/lib -lSDL -lopengl32 -o $(EXEC) > EXEC = 1-1.exe > OBJECTS = simple_1-1.o > > all: $(OBJECTS) > $(CXX) $^ $(LDFLAGS) > > %.o: %.cpp > $(CXX) $(CXXFLAGS) $< > > clean: > rm -f $(OBJECTS) $(EXEC) *~ *.stackdump > > This compiles, links, and runs just fine. However, now I want to use one > of the wgl-functions (namely wglGetProcAddress). For that I have to > include . The program compiles, but the linker fails with: > $ make > g++ -Wall -Wextra -std=c++98 -pedantic -g -O0 -I ~/SDL-1.2.11/include -c > simple_1-1.cpp > g++ simple_1-1.o -L ~/SDL-1.2.11/lib -lSDL -lopengl32 -o 1-1.exe > /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(libcmain.o):(.text+0xab): > undefined reference to `_WinMain AT 16' OK, so I tried replacing the main() function with a WinMain() and now it links under cygwin too. This is not necessary under MSVC++, though. I wonder if it can be solved? Right now I use #ifdef:s to work around it. > > I tried adding -lSDLmain and -mwindows to the linker options, but it > didn't help. Still the same linking error. Posting this to both the > cygwin and sdl mailing list, hope that it doesn't offend anyone. > Attaching the working program and Makefile. What must I do to get it to > work? Works just fine under MSVC++ but I'd much rather use cygwin/gcc. > > / E > > > ------------------------------------------------------------------------ > > #include > #include > > #include > > static void > display() > { > glClear(GL_COLOR_BUFFER_BIT); > > glBegin(GL_POLYGON); > glVertex2f(-0.5f,-0.5f); > glVertex2f(-0.5f, 0.5f); > glVertex2f( 0.5f, 0.5f); > glVertex2f( 0.5f,-0.5f); > glEnd(); > > SDL_GL_SwapBuffers(); > } > > int > main(int argc, char *argv[]) > { > (void)argc; > (void)argv; > > int retval = SDL_Init(SDL_INIT_VIDEO); > > assert(retval == 0); > > SDL_Surface *surface = SDL_SetVideoMode(640, 480, 0, SDL_OPENGL); > > assert(surface != NULL); > > SDL_WM_SetCaption("Simple SDL/OpenGL demo", NULL); > > SDL_Event event; > > while (true) > { > while (SDL_PollEvent(&event)) > { > switch (event.type) > { > case SDL_QUIT: > { > SDL_Quit(); > > exit(EXIT_SUCCESS); > } > } > } > > display(); > } > > assert(0); /* Not reached. */ > } > > > ------------------------------------------------------------------------ > > CXX = g++ > CXXFLAGS = -Wall -Wextra -std=c++98 -pedantic -g -O0 -I ~/SDL-1.2.11/include -c > LDFLAGS = -L ~/SDL-1.2.11/lib -lSDL -lopengl32 -o $(EXEC) > EXEC = 1-1.exe > OBJECTS = simple_1-1.o > > all: $(OBJECTS) > $(CXX) $^ $(LDFLAGS) > > %.o: %.cpp > $(CXX) $(CXXFLAGS) $< > > clean: > rm -f $(OBJECTS) $(EXEC) *~ *.stackdump > > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/