Converted binary sample project to C++ to demonstrate how to use C++11 and static libstdc++.
This commit is contained in:
parent
efbbcd3786
commit
a3c1a5eaa3
|
@ -3,7 +3,7 @@
|
|||
curdir=`pwd`
|
||||
rm -rf buildtmp
|
||||
mkdir buildtmp
|
||||
~/meson/meson.py buildtmp --buildtype=release --prefix=/tmp/myapp --libdir=lib
|
||||
LDFLAGS=-static-libstdc++ ~/meson/meson.py buildtmp --buildtype=release --prefix=/tmp/myapp --libdir=lib
|
||||
ninja -C buildtmp install
|
||||
rm -rf buildtmp
|
||||
cd /tmp/
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
project('myapp', 'c')
|
||||
project('myapp', 'cpp')
|
||||
|
||||
sdl = dependency('sdl2')
|
||||
|
||||
if meson.get_compiler('c').get_id() != 'msvc'
|
||||
if meson.get_compiler('cpp').get_id() != 'msvc'
|
||||
add_global_arguments('-std=c++11', language : 'cpp')
|
||||
endif
|
||||
|
||||
|
@ -25,6 +25,6 @@ if host.name() == 'linux'
|
|||
endif
|
||||
|
||||
|
||||
prog = executable('myapp', 'myapp.c',
|
||||
prog = executable('myapp', 'myapp.cpp',
|
||||
dependencies : sdl,
|
||||
install : true)
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
#include<SDL.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
SDL_Window *window;
|
||||
SDL_Surface *screenSurface;
|
||||
SDL_Event e;
|
||||
int keepGoing = 1;
|
||||
if(SDL_Init( SDL_INIT_VIDEO ) < 0) {
|
||||
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow( "My application", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN );
|
||||
|
||||
screenSurface = SDL_GetWindowSurface( window );
|
||||
|
||||
while(keepGoing) {
|
||||
while(SDL_PollEvent(&e) != 0) {
|
||||
if(e.type == SDL_QUIT) {
|
||||
keepGoing = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0x00, 0x00 ) );
|
||||
SDL_UpdateWindowSurface( window );
|
||||
SDL_Delay(100);
|
||||
}
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#include<SDL.h>
|
||||
#include<memory>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
SDL_Surface *screenSurface;
|
||||
SDL_Event e;
|
||||
int keepGoing = 1;
|
||||
if(SDL_Init( SDL_INIT_VIDEO ) < 0) {
|
||||
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
|
||||
}
|
||||
atexit(SDL_Quit);
|
||||
|
||||
std::unique_ptr<SDL_Window, void(*)(SDL_Window*)> window(SDL_CreateWindow( "My application", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN), SDL_DestroyWindow);
|
||||
screenSurface = SDL_GetWindowSurface(window.get());
|
||||
|
||||
while(keepGoing) {
|
||||
while(SDL_PollEvent(&e) != 0) {
|
||||
if(e.type == SDL_QUIT) {
|
||||
keepGoing = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0x00, 0x00));
|
||||
SDL_UpdateWindowSurface(window.get());
|
||||
SDL_Delay(100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue