Home » Community » Newbie corner » How to configure for SDL2 project?  
	
		
		
			| Re: How to configure for SDL2 project? [message #57062 is a reply to message #57027] | 
			Wed, 19 May 2021 06:01    | 
		 
		
			
				
				
				
					
						  
						flim
						 Messages: 5 Registered: May 2021  Location: Hong Kong
						
					 | 
					Promising Member  | 
					 | 
		 
		 
	 | 
 
	
		I test the nightly build today, I create a new packagew with SDL in MyApp, the package build successfully. 
 
But when I build this code, the linker failed. Any idea? 
 
 (): Linking has failed 
 (): lld-link: error: undefined symbol: SDL_main 
 (): >>> referenced by c:\projects\sdl\src\main\windows\sdl_windows_main.c:175 
 (): >>>               SDL2main.lib(SDL_windows_main.obj):(main_getcmdline) 
 (): clang-11: error: linker command failed with exit code 1 (use -v to see invocation) 
 
#ifdef _WIN32
#include <SDL.h>
#else
#include <SDL2/SDL.h>
#endif
#include <stdbool.h>
#include <stdio.h>
bool is_running = false;
SDL_Window* window = NULL;
SDL_Renderer* renderer = NULL;
bool initialize_window(void) {
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0 ) {
        fprintf(stderr, "Error initializing SDL.\n");
        return false;
    }
    // Create a SDL Window
    window = SDL_CreateWindow(
        NULL,
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        800,
        600,
        SDL_WINDOW_BORDERLESS
    );
    
    if (!window) {
        fprintf(stderr, "Error creating SDL window.\n");
        return false;
    }
    // Create a SDL renderer
    renderer = SDL_CreateRenderer(window, -1, 0);
    if (!renderer) {
        fprintf(stderr, "Error creating SDL renderer.\n");
        return false;
    }
    return true;
}
void setup(void) {
}
void process_input(void) {
    SDL_Event event;
    SDL_PollEvent(&event);
    switch (event.type) {
    case SDL_QUIT:
        is_running = false;
        break;
    case SDL_KEYDOWN:
        if (event.key.keysym.sym == SDLK_ESCAPE)
            is_running = false;
        break;
    }
}
void update(void) {
}
void render(void) {
    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    SDL_RenderClear(renderer);
    SDL_RenderPresent(renderer);
}
int main(void) {
    is_running = initialize_window();
    setup();
    while (is_running) {
        process_input();
        update();
        render();
    }
    return 0;
}
 
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
  
 
	
	  | 
	 | 
	
		How to configure for SDL2 project?
		By:  flim on Fri, 14 May 2021 16:03  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  mirek on Fri, 14 May 2021 16:15  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  flim on Sat, 15 May 2021 12:50  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  mirek on Sat, 15 May 2021 13:42  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  flim on Sat, 15 May 2021 14:42  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  mirek on Sat, 15 May 2021 20:35  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  Klugier on Sun, 16 May 2021 13:36  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  Klugier on Sun, 16 May 2021 13:42  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  Klugier on Sun, 16 May 2021 14:04  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  flim on Wed, 19 May 2021 06:01  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  mirek on Wed, 19 May 2021 11:40  
	 | 
 
	  | 
	 | 
	
		Re: How to configure for SDL2 project?
		By:  flim on Wed, 19 May 2021 14:13  
	 | 
  
Goto Forum:
 
 Current Time: Tue Nov 04 09:19:23 CET 2025 
 Total time taken to generate the page: 0.04905 seconds 
 |