meson 链接库

文章介绍了如何使用Meson构建系统来编译一个C++项目,该项目包含了SDL2图形库、fmt格式化库和zlib压缩库。还提到了使用pkg-config来查找和管理依赖,以及在VisualStudioCode中进行代码格式化和文件导航的操作。
摘要由CSDN通过智能技术生成

before

meson usage

  • check src dir meson.build and see target link library

meson build / meson --reconfigure build

using pkg-config to find package

  1. pkg-config --cflags --libs sdl2
  2. pkg-config --list-all | grep sdl2
  3. pkg-config --modversion sdl2

try sdl2 light demo

vscode shortcuts

  • format on linux in vscode: ctrl + shift + I
  • goto file: ctrl + p

project

// file:main.cpp --src/main.cpp
#include <iostream>
using namespace std;
#include <fmt/format.h>
// zib may not use
#include <zlib.h>
#include <SDL2/SDL.h>

void test_meson_can_work()
{
    // test fmt
    cout << fmt::format("{}", 1) << endl;
    // end test fmt
}

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;
}
# file: meson.build --src/meson.build
ss_sources = [
  'main.cpp',
]
# meson apis
# message('fuck')
# message('I dont know what is going on')

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,
)
# this?
# exe = executable('zlibprog', 'prog.c', dependencies : zdep)
 
#file:meson.build --meson.build
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值