before
meson usage
- check src dir meson.build and see target link library
meson build / meson --reconfigure build
using pkg-config to find package
- pkg-config --cflags --libs sdl2
- pkg-config --list-all | grep sdl2
- pkg-config --modversion sdl2
try sdl2 light demo
vscode shortcuts
- format on linux in vscode: ctrl + shift + I
- goto file: ctrl + p
project
#include <iostream>
using namespace std;
#include <fmt/format.h>
#include <zlib.h>
#include <SDL2/SDL.h>
void test_meson_can_work()
{
cout << fmt::format("{}", 1) << endl;
}
int main()
{
if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
cout << "error: init" << endl;
SDL_Window *window = SDL_CreateWindow("hello", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 600, 600, SDL_WINDOW_ALLOW_HIGHDPI);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetRenderDrawColor(renderer, 64, 255, 128, 255);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
if (NULL == window)
{
cout << "error:window create" << SDL_GetError() << endl;
}
SDL_Event window_event;
while (1)
{
if (SDL_PollEvent(&window_event))
{
if (SDL_QUIT == window_event.type)
{
break;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
ss_sources = [
'main.cpp',
]
z_dep = dependency('zlib', version : '>=1.2.8')
fmt_dep = dependency('fmt',version: '>=9.1.0')
sdl_dep = dependency('sdl2',)
executable('ss', ss_sources,
dependencies: [z_dep,fmt_dep,sdl_dep],
install: true,
)
project('ss', ['cpp', 'c'],
version: '0.1.0',
meson_version: '>= 0.62.0',
default_options: [ 'warning_level=2', 'werror=false', 'cpp_std=gnu++2a', ],
)
subdir('src')
then use ninja to build exe file in builddir
- using
pkg-config
for more example