Meson构建系统中使用pkg-config的最佳实践是什么?
Meson中pkg-config的最佳使用实践
在Makefile中,可以通过如下写法获取依赖库:
LIBS:= $(shell pkg-config --libs $(PKGS))
很多人一开始在meson.build中不知道如何实现类似的简洁写法,最容易想到的方案是手动调用run_command执行pkg-config,示例代码如下:
r = run_command('pkg-config', '--cflags', 'gstreamer-1.0 gstreamer-video-1.0') if r.returncode() != 0 # 调用失败处理 errortxt = r.stderr().strip() message(errortxt) endif output = r.stdout().strip().split(' ') message(output) foreach inc : output add_global_arguments(inc, language : 'c') endforeach
官方推荐最佳实践
不需要手动封装run_command逻辑,Meson内置的dependency()接口已经原生支持pkg-config,直接调用即可,写法非常简洁:
dependency('gstreamer-video-1.0', 'pkg-config')
配置验证注意事项
上述配置的所有效果会体现在build.ninja的链接参数中,示例如下:
LINK_ARGS = -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group -lm -Wl,-rpath,/opt/nvidia/deepstream/deepstream-5.1/lib:/usr/local/cuda-10.2/lib64 -Wl,-rpath-link,/opt/nvidia/deepstream/deepstream-5.1/lib -Wl,-rpath-link,/usr/local/cuda-10.2/lib64 /opt/nvidia/deepstream/deepstream-5.1/lib/libnvdsgst_meta.so /opt/nvidia/deepstream/deepstream-5.1/lib/libnvds_meta.so /opt/nvidia/deepstream/deepstream-5.1/lib/libnvdsgst_helper.so /usr/lib/aarch64-linux-gnu/libgstreamer-1.0.so /usr/lib/aarch64-linux-gnu/libgobject-2.0.so /usr/lib/aarch64-linux-gnu/libglib-2.0.so /usr/lib/gcc/aarch64-linux-gnu/7/../../../aarch64-linux-gnu/libcuda.so /usr/local/cuda-10.2/lib64/libcudart.so /usr/lib/aarch64-linux-gnu/libgstrtspserver-1.0.so /usr/lib/aarch64-linux-gnu/libgstvideo-1.0.so /usr/lib/aarch64-linux-gnu/libgstbase-1.0.so -Wl,--end-group
但这些链接参数不会体现在compile_commands.json中,该文件仅包含编译阶段的参数,示例如下:
[ { "directory": "/home/ubuntu/work/deepstream-5.1/sources/apps/sample_apps/test3_meson/build", "command": "cc -Itest1.p -I. -I.. -I/usr/local/cuda-10.2/include -I../../../../includes -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include -I/usr/include/orc-0.4 -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -g -DPLATFORM_TEGRA -pthread -MD -MQ test1.p/deepstream_test3_app.c.o -MF test1.p/deepstream_test3_app.c.o.d -o test1.p/deepstream_test3_app.c.o -c ../deepstream_test3_app.c", "file": "../deepstream_test3_app.c" } ]
因此修改meson.build后,建议优先查看build.ninja中的配置生效情况。
内容的提问来源于stack exchange,提问作者alen
相关产品推荐
相关产品推荐

