系列索引地址:Wayland开发入门教程索引
上一篇:Wayland开发入门教程05:调试工具
废话说完了,接下来正式进入开发流程,一般编程开发的第一步就是Hello World
。
本文主要测试Wayland的头文件、库能否正确链接。
依赖
先安装后续开发必要的依赖软件包
Ubuntu21.10
1
| sudo apt install libwayland-dev libegl1-mesa-dev libglm-dev wayland-protocols libwayland-bin extra-cmake-modules
|
测试代码
1 2 3 4 5 6 7 8 9
| #include <wayland-server.h> #include <wayland-client.h>
#include <iostream> using namespace std;
int main(){ cout<<"Hello world"<<endl; }
|
编译方法
Qt
Meson
1 2 3 4 5 6
| project('example_wayland', 'c', default_options : 'c_std=gnu11') dependency('wayland-client') c_flags = ['-g', '-Og'] ld_flags = ['-lwayland-client', '-lrt', '-lxkbcommon', '-lm'] src = ['src/main.c', 'src/xdg-shell-unstable-v6-client-protocol.c', 'src/int_set.c'] executable('example_wayland', src, c_args : c_flags, link_args : ld_flags)
|
CMake
Makefile
1 2
| all: g++ -o helloworld helloworld.cpp -lwayland-client -lwayland-server -lwayland-cursor -lwayland-egl
|
编译运行
1 2 3 4
| hyper@ubuntu:~/Nutstore Files/Nutstore/Wayland$ make g++ -o helloworld helloworld.cpp -lwayland-client -lwayland-server -lwayland-cursor -lwayland-egl hyper@ubuntu:~/Nutstore Files/Nutstore/Wayland$ ./helloworld Hello world
|
没有报错、没有异常,表示wayland相关头文件和库文件位置包含没有错。
完整代码在Wayland_Freshman下的06.hellow world
中。
下一篇:Wayland开发入门教程07:连接server