I am trying to use clang on Windows to compile and link an SDL2 application.
The reason for this is to try and keep my development environment consistent with other team members who are using OSX with XCode (compiling with clang). Since the Visual C++ compiler is much less strict than the clang compiler I could potentially be committing changes that will not compile under clang.
I would prefer not to have to install VS 2015 to use the experimental LLVM build environment: (link removed)
I have installed the LLVM/clang tools on windows (not built from source, just downloaded binaries from here: (link removed)) and can successfully build and run a "hello world" console application using clang.
What I would like to do, is to have a batch file that allows me to build and link with clang periodically to make sure my code will be safe to commit.
When linking even a simple single file SDL2 application, I receive the following linker error:
LINK : fatal error LNK1561: entry point must be defined
clang++.exe: error: linker command failed with exit code 1561 (use -v to see invocation)
CALL "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat"
clang++ -std=c++11 main.cpp -I./include/SDL2 -L./lib -lSDL2main -lSDL2
/*This source code copyrighted by Lazy Foo' Productions (2004-2015)
and may not be redistributed without written permission.*/
//Using SDL and standard IO
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main( int argc, char* args )
//The window we'll be rendering to
SDL_Window* window = NULL;
//The surface contained by the window
SDL_Surface* screenSurface = NULL;
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( window == NULL )
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
//Get window surface
screenSurface = SDL_GetWindowSurface( window );
//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
//Update the surface
SDL_UpdateWindowSurface( window );
//Wait two seconds
SDL_Delay( 2000 );
SDL_DestroyWindow( window );
//Quit SDL subsystems
MSVC linker uses
/subsystem:windows option to set GUI mode (and use
WinMain instead of
main), so you'll need to pass it:
clang++ -std=c++11 main.cpp -I./include/SDL2 -L./lib -lSDL2main -lSDL2 -Xlinker /subsystem:windows