gpt4 book ai didi

c - 将 pg_config 与 waf 一起使用

转载 作者:太空宇宙 更新时间:2023-11-03 23:46:16 26 4
gpt4 key购买 nike

我使用 waf作为我的构建系统,我想使用 Postgres 编译一个小的 C 程序。我在我的程序中包含了 postgres.h,所以我需要在我的 wscript 文件中找到它的路径。我知道我可以通过运行获得我需要的路径:

pg_config --includedir-server

这给了我:

/usr/include/postgresql/9.3/server

所以我想我可以使用这样的东西:

cfg.check_cfg(
path='pg_config',
package='',
uselib_store='PG',
args='--includedir-server',
)

然后通过以下方式构建我的程序:

bld.program(
source=['testpg.c'],
target='testpg',
includes=['.', '../src'],
use=['PQ', 'PG'],
)

但这失败了 postgres.h: No such file or directory。我运行了 ./waf -v 并确认没有将正确的 -I 标志传递给 gcc。我猜这是因为 pg_config 没有在它返回的路径中添加 -I 前缀。有没有办法让 waf 添加前缀,或者让 pg_config 添加前缀?

最佳答案

如果 pg_config 具有 pkg_config 之类程序的标准输出(即输出类似 -Ixxx -Iyyy 的内容),您的代码就可以工作,具有 check_cfg 解析这种输出。

由于没有复杂的解析,你可以去:

import subprocess

includes = subprocess.check_output(["pg_config", "--includedir-server"])
includes.replace("\n", "")

conf.env.INCLUDES_PG = [includes]

然后使用它:

bld.program(
source=['testpg.c'],
target='testpg',
use=['PG'],
)

参见 library integration in the waf book .它解释了使其起作用的命名规则。

你可以写一个小插件来简化使用:)

关于c - 将 pg_config 与 waf 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32886768/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com