⛳
【C 言語】【Zig】nghttp2 のバージョン番号を表示する
nghttp2 は HTTP/2 クライアントやサーバーを実装するために使われている。Debian では libnghttp2-dev
という名前のパッケージが用意されている。
sudo apt install libnghttp2-dev
コードを書いてみる
test.c
#include <stdio.h>
#include <nghttp2/nghttp2.h>
int main() {
nghttp2_info *info = nghttp2_version(0);
printf("%s\n", info->version_str);
return 0;
}
コンパイルしてみよう
clang -lnghttp2 test.c -o test
続いて Zig のコードを書く
const std = @import("std");
const print = std.debug.print;
const nghttp2 = @cImport({
@cInclude("nghttp2/nghttp2.h");
});
pub fn main() !void {
const info = nghttp2.nghttp2_version(0);
print("{s}\n", .{info.*.version_str});
}
ビルドは次の通り
zig run test.zig -lc -lnghttp2
Discussion