Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何配置pg_config/pgxs/make在Makefile中拾取cppfagas和CFLAGS以构建Postgres C/C++;扩展?_C++_C_Postgresql_Postgresql 12 - Fatal编程技术网

C++ 如何配置pg_config/pgxs/make在Makefile中拾取cppfagas和CFLAGS以构建Postgres C/C++;扩展?

C++ 如何配置pg_config/pgxs/make在Makefile中拾取cppfagas和CFLAGS以构建Postgres C/C++;扩展?,c++,c,postgresql,postgresql-12,C++,C,Postgresql,Postgresql 12,我想添加编译器标志来构建我的Postgres C/C++扩展。我已经尝试过标准的Makefile实践,但是pg_config没有拾取我添加的任何编译器标志 生成文件如下所示: 1 # the extensions name 2 EXTENSION = extension_one 3 DATA = $(wildcard *--*.sql) # script files to install 4 TESTS = $(wi

我想添加编译器标志来构建我的Postgres C/C++扩展。我已经尝试过标准的Makefile实践,但是pg_config没有拾取我添加的任何编译器标志

生成文件如下所示:

  1 # the extensions name
  2 EXTENSION     = extension_one
  3 DATA          = $(wildcard *--*.sql)            # script files to install
  4 TESTS         = $(wildcard test/sql/*.sql)      # use appropriate testfiles
  5 
  6 CFLAGS   = -std=c99
  7 CPPFLAGS = -std=c++17
  8 
  9 # find the sql and expected directories under test
 10 # load plpgsql into test db
 11 # load extension into test db
 12 # dbname
 13 REGRESS_OPTS  = --inputdir=test         \
 14                 --load-extension=extension_one \
 15                 --load-language=plpgsql
 16 REGRESS       = $(patsubst test/sql/%.sql,%,$(TESTS))
 17 OBJS          = $(patsubst %.c,%.o,$(wildcard src/*.c)) # object files
 18 # final shared library to be build from multiple source files (OBJS)
 19 MODULE_big    = $(EXTENSION)
 20 
 21 
 22 # postgres build stuff
 23 PG_CONFIG = pg_config
 24 PGXS := $(shell $(PG_CONFIG) --pgxs)
 25 include $(PGXS)
>pg_config
BINDIR = /usr/lib/postgresql/12/bin
DOCDIR = /usr/share/doc/postgresql-doc-12
HTMLDIR = /usr/share/doc/postgresql-doc-12
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/12/server
LIBDIR = /usr/lib/x86_64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/12/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/12/man
SHAREDIR = /usr/share/postgresql/12
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/12/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=/usr/include' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-silent-rules' '--libdir=/usr/lib/x86_64-linux-gnu' '--libexecdir=/usr/lib/x86_64-linux-gnu' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-icu' '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' 'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/12/man' '--docdir=/usr/share/doc/postgresql-doc-12' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/12' '--bindir=/usr/lib/postgresql/12/bin' '--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--with-extra-version= (Ubuntu 12.4-0ubuntu0.20.04.1)' '--enable-nls' '--enable-integer-datetimes' '--enable-thread-safety' '--enable-tap-tests' '--enable-debug' '--enable-dtrace' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' 'LLVM_CONFIG=/usr/bin/llvm-config-10' 'CLANG=/usr/bin/clang-10' '--with-systemd' '--with-selinux' 'MKDIR_P=/bin/mkdir -p' 'TAR=/bin/tar' 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' '--with-gssapi' '--with-ldap' '--with-includes=/usr/include/mit-krb5' '--with-libs=/usr/lib/mit-krb5' '--with-libs=/usr/lib/x86_64-linux-gnu/mit-krb5' 'build_alias=x86_64-linux-gnu' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
CC = gcc
CPPFLAGS = -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -L/usr/lib/llvm-10/lib -L/usr/lib/x86_64-linux-gnu/mit-krb5 -Wl,--as-needed
LDFLAGS_EX = 
LDFLAGS_SL = 
LIBS = -lpgcommon -lpgport -lpthread -lselinux -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -ledit -lrt -lcrypt -ldl -lm 
VERSION = PostgreSQL 12.4 (Ubuntu 12.4-0ubuntu0.20.04.1)
pg_配置环境变量设置如下:

  1 # the extensions name
  2 EXTENSION     = extension_one
  3 DATA          = $(wildcard *--*.sql)            # script files to install
  4 TESTS         = $(wildcard test/sql/*.sql)      # use appropriate testfiles
  5 
  6 CFLAGS   = -std=c99
  7 CPPFLAGS = -std=c++17
  8 
  9 # find the sql and expected directories under test
 10 # load plpgsql into test db
 11 # load extension into test db
 12 # dbname
 13 REGRESS_OPTS  = --inputdir=test         \
 14                 --load-extension=extension_one \
 15                 --load-language=plpgsql
 16 REGRESS       = $(patsubst test/sql/%.sql,%,$(TESTS))
 17 OBJS          = $(patsubst %.c,%.o,$(wildcard src/*.c)) # object files
 18 # final shared library to be build from multiple source files (OBJS)
 19 MODULE_big    = $(EXTENSION)
 20 
 21 
 22 # postgres build stuff
 23 PG_CONFIG = pg_config
 24 PGXS := $(shell $(PG_CONFIG) --pgxs)
 25 include $(PGXS)
>pg_config
BINDIR = /usr/lib/postgresql/12/bin
DOCDIR = /usr/share/doc/postgresql-doc-12
HTMLDIR = /usr/share/doc/postgresql-doc-12
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/12/server
LIBDIR = /usr/lib/x86_64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/12/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/12/man
SHAREDIR = /usr/share/postgresql/12
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/12/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=/usr/include' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-silent-rules' '--libdir=/usr/lib/x86_64-linux-gnu' '--libexecdir=/usr/lib/x86_64-linux-gnu' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-icu' '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' 'PYTHON=/usr/bin/python3' '--mandir=/usr/share/postgresql/12/man' '--docdir=/usr/share/doc/postgresql-doc-12' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/12' '--bindir=/usr/lib/postgresql/12/bin' '--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--with-extra-version= (Ubuntu 12.4-0ubuntu0.20.04.1)' '--enable-nls' '--enable-integer-datetimes' '--enable-thread-safety' '--enable-tap-tests' '--enable-debug' '--enable-dtrace' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' '--with-llvm' 'LLVM_CONFIG=/usr/bin/llvm-config-10' 'CLANG=/usr/bin/clang-10' '--with-systemd' '--with-selinux' 'MKDIR_P=/bin/mkdir -p' 'TAR=/bin/tar' 'CFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' 'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now' '--with-gssapi' '--with-ldap' '--with-includes=/usr/include/mit-krb5' '--with-libs=/usr/lib/mit-krb5' '--with-libs=/usr/lib/x86_64-linux-gnu/mit-krb5' 'build_alias=x86_64-linux-gnu' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'
CC = gcc
CPPFLAGS = -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include/mit-krb5
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -L/usr/lib/llvm-10/lib -L/usr/lib/x86_64-linux-gnu/mit-krb5 -Wl,--as-needed
LDFLAGS_EX = 
LDFLAGS_SL = 
LIBS = -lpgcommon -lpgport -lpthread -lselinux -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -ledit -lrt -lcrypt -ldl -lm 
VERSION = PostgreSQL 12.4 (Ubuntu 12.4-0ubuntu0.20.04.1)
由于pg_config显示“CFLAGS”和“CPPFLAGS”,并且官方文档()说使用这些标志,这就是我尝试过的,但是当我运行make时,它不会拾取它们。注意:我已经尝试了正常的“=”和上面链接的文档中建议的“+=”。什么也没有

当我运行make时,我得到:

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer -fPIC -I. -I./ -I/usr/include/postgresql/12/server -I/usr/include/postgresql/internal  -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include/mit-krb5  -c -o src/extension_one.o src/extension_one.c
注意:我在“数据库管理员”堆栈交换中问了这个问题,但现在意识到在这里问这个问题可能更合适


注意:这是一个很好的Postgresql C扩展示例,如果您需要一个示例可以使用它:

我不是一个DB爱好者,但在Gentoo的编译工作中,我也有一段时间。这引起了我的好奇心。 这是我的2美分:

长话短说,您应该在
Makefile

我怎么知道的

$pg\u config--帮助
pg_config提供有关已安装的PostgreSQL版本的信息。
关键字正在提供有关已安装版本的信息。因此,您额外的
CFLAGS
将不会显示在那里

但是我注意到Makefile拉取了
pg_config--pgxs
的输出来扩展Makefile。我的发行版中的输出是:
/usr/lib64/pgsql/pgxs/src/makefiles/pgxs.mk

所以我在我的编辑器中打开了它,下面是一个片段:

#   PG_CPPFLAGS -- will be prepended to CPPFLAGS
#   PG_CFLAGS -- will be appended to CFLAGS
#   PG_CXXFLAGS -- will be appended to CXXFLAGS
#   PG_LDFLAGS -- will be prepended to LDFLAGS

非常感谢。我自己永远也不会发现这一点。这是可行的,而且参考文件(pgxs.mk)中有很多好东西。我很高兴我能提供帮助。