delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/10/23/11:08:06

X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Lilja <mindcooler AT gmail DOT com>
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: <ehilr4$1ta$1@sea.gmane.org>
References: <ehgk06$isp$1 AT sea DOT gmane DOT org>
Mime-Version: 1.0
User-Agent: Thunderbird 1.5.0.7 (Windows/20060909)
In-Reply-To: <ehgk06$isp$1@sea.gmane.org>
Cc: sdl AT libsdl DOT org
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 <windows.h>
> #include <SDL.h>
> #include <GL/gl.h>
> 
> #include <cassert>
> 
> 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 <windows.h>. 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 <SDL.h>
> #include <GL/gl.h>
> 
> #include <cassert>
> 
> 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019