ubuntu下编译libpq和libpqxx库

ubuntu下编译libpq和libpqxx库,用于链接人大金仓

上篇文章验证了libpqxx可以链接人大金仓数据库,这篇文章尝试自己编译libpq和libpqxx库。

文章目录

  • ubuntu下编译libpq和libpqxx库,用于链接人大金仓
    • libpq
      • 下载libpq库
      • 看看有没有libpq库
      • 编译libpq
      • readline问题
      • 编译postgresql
      • 尝试单独编译libpq库
    • libpqxx
      • 下载libpqxx
      • 选版本
      • configure --help
      • 编译配置
      • 编译
      • 再编译
      • 再再编译
      • 看看依赖
    • 好像没有问题,收工

libpq

下载libpq库

找了以打晌儿,就是找不到,咋办?放弃吧,等等,好像在postgresql源码中。

下载源码看看有没有。

官网走起:https://www.postgresql.org/

两会期间,网速贼慢,物理吐槽,等版半天打开了一次,就不知道怎么遭到下载地址了。

先按照ubuntu18源中的版本进行下载。

$ dpkg -L libpq-dev | grep -F ".pc" | xargs cat
Name: libpq
Description: PostgreSQL libpq library
Url: http://www.postgresql.org/
Version: 10.23
Requires: 
Requires.private: 
Cflags: -I/usr/include/postgresql
Libs: -L/usr/lib/x86_64-linux-gnu -lpq
Libs.private: -L/usr/lib/x86_64-linux-gnu/mit-krb5 -lssl -lcrypto -lgssapi_krb5 -lcrypt -lldap_r

最终的下载位置为:https://ftp.postgresql.org/pub/source/v10.23/postgresql-10.23.tar.gz
需要其他版本呢自己找,自己在官网找好了。

看看有没有libpq库

解压后,搜一下libpq关键字

# root @ ubuntu in ~/workspace/postgresql-10.23 [8:10:53] 
$ find . -name "*libpq*"
./src/backend/libpq
./src/backend/replication/libpqwalreceiver
./src/backend/replication/libpqwalreceiver/libpqwalreceiver.c
./src/interfaces/libpq
./src/interfaces/libpq/libpq-fe.h
./src/interfaces/libpq/libpq-int.h
./src/interfaces/libpq/libpq.rc.in
./src/interfaces/libpq/libpq-events.h
./src/interfaces/libpq/libpq-events.c
./src/interfaces/libpq/libpqddll.def
./src/interfaces/libpq/libpqdll.def
./src/interfaces/libpq/libpq-dist.rc
./src/include/libpq
./src/include/libpq/libpq-be.h
./src/include/libpq/libpq.h
./src/include/libpq/libpq-fs.h
./src/bin/pg_rewind/libpq_fetch.c
./src/test/examples/testlibpq3.sql
./src/test/examples/testlibpq2.c
./src/test/examples/testlibpq2.sql
./src/test/examples/testlibpq.c
./src/test/examples/testlibpq4.c
./src/test/examples/testlibpq3.c
./doc/src/sgml/html/libpq-copy.html
./doc/src/sgml/html/libpq-connect.html
./doc/src/sgml/html/libpq.html
./doc/src/sgml/html/libpq-example.html
./doc/src/sgml/html/libpq-fastpath.html
./doc/src/sgml/html/libpq-misc.html
./doc/src/sgml/html/libpq-events.html
./doc/src/sgml/html/libpq-threading.html
./doc/src/sgml/html/libpq-pgpass.html
./doc/src/sgml/html/libpq-status.html
./doc/src/sgml/html/libpq-cancel.html
./doc/src/sgml/html/libpq-ldap.html
./doc/src/sgml/html/libpq-control.html
./doc/src/sgml/html/libpq-build.html
./doc/src/sgml/html/libpq-ssl.html
./doc/src/sgml/html/libpq-envars.html
./doc/src/sgml/html/libpq-async.html
./doc/src/sgml/html/libpq-notify.html
./doc/src/sgml/html/libpq-notice-processing.html
./doc/src/sgml/html/libpq-exec.html
./doc/src/sgml/html/libpq-pgservice.html
./doc/src/sgml/html/libpq-single-row-mode.html
./doc/src/sgml/libpq.sgml

浪费了好大一会儿时间,原来在数据库的源码库中。

编译libpq

怎么单独编译libpq呢。
./configure --help 走起

# root @ ubuntu in ~/workspace/postgresql-10.23 [8:14:49] 
$ ./configure --help
`configure' configures PostgreSQL 10.23 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/pgsql]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/pgsql/bin', `/usr/local/pgsql/lib' etc.  You can specify
an installation prefix other than `/usr/local/pgsql' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/postgresql]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --disable-integer-datetimes
                          obsolete option, no longer supported
  --enable-nls[=LANGUAGES]
                          enable Native Language Support
  --disable-rpath         do not embed shared library search path in
                          executables
  --disable-spinlocks     do not use spinlocks
  --disable-atomics       do not use atomic operations
  --disable-strong-random do not use a strong random number source
  --enable-debug          build with debugging symbols (-g)
  --enable-profiling      build with profiling enabled
  --enable-coverage       build with coverage testing instrumentation
  --enable-dtrace         build with DTrace support
  --enable-tap-tests      enable TAP tests (requires Perl and IPC::Run)
  --enable-depend         turn on automatic dependency tracking
  --enable-cassert        enable assertion checks (for debugging)
  --disable-thread-safety disable thread-safety in client libraries
  --disable-largefile     omit support for large files
  --disable-float4-byval  disable float4 passed by value
  --disable-float8-byval  disable float8 passed by value

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-extra-version=STRING
                          append STRING to version
  --with-template=NAME    override operating system template
  --with-includes=DIRS    look for additional header files in DIRS
  --with-libraries=DIRS   look for additional libraries in DIRS
  --with-libs=DIRS        alternative spelling of --with-libraries
  --with-pgport=PORTNUM   set default port number [5432]
  --with-blocksize=BLOCKSIZE
                          set table block size in kB [8]
  --with-segsize=SEGSIZE  set table segment size in GB [1]
  --with-wal-blocksize=BLOCKSIZE
                          set WAL block size in kB [8]
  --with-wal-segsize=SEGSIZE
                          set WAL segment size in MB [16]
  --with-CC=CMD           set compiler (deprecated)
  --with-icu              build with ICU support
  --with-tcl              build Tcl modules (PL/Tcl)
  --with-tclconfig=DIR    tclConfig.sh is in DIR
  --with-perl             build Perl modules (PL/Perl)
  --with-python           build Python modules (PL/Python)
  --with-gssapi           build with GSSAPI support
  --with-krb-srvnam=NAME  default service principal name in Kerberos (GSSAPI)
                          [postgres]
  --with-pam              build with PAM support
  --with-bsd-auth         build with BSD Authentication support
  --with-ldap             build with LDAP support
  --with-bonjour          build with Bonjour support
  --with-openssl          build with OpenSSL support
  --with-selinux          build with SELinux support
  --with-systemd          build with systemd support
  --without-readline      do not use GNU Readline nor BSD Libedit for editing
  --with-libedit-preferred
                          prefer BSD Libedit over GNU Readline
  --with-uuid=LIB         build contrib/uuid-ossp using LIB (bsd,e2fs,ossp)
  --with-ossp-uuid        obsolete spelling of --with-uuid=ossp
  --with-libxml           build with XML support
  --with-libxslt          use XSLT support when building contrib/xml2
  --with-system-tzdata=DIR
                          use system time zone data in DIR
  --without-zlib          do not use Zlib
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L if you have libraries in a
              nonstandard directory 
  LIBS        libraries to pass to the linker, e.g. -l
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I if
              you have headers in a nonstandard directory 
  CPP         C preprocessor
  PKG_CONFIG  path to pkg-config utility
  PKG_CONFIG_PATH
              directories to add to pkg-config's search path
  PKG_CONFIG_LIBDIR
              path overriding pkg-config's built-in search path
  ICU_CFLAGS  C compiler flags for ICU, overriding pkg-config
  ICU_LIBS    linker flags for ICU, overriding pkg-config
  XML2_CONFIG path to xml2-config utility
  XML2_CFLAGS C compiler flags for XML2, overriding pkg-config
  XML2_LIBS   linker flags for XML2, overriding pkg-config
  LDFLAGS_EX  extra linker flags for linking executables only
  LDFLAGS_SL  extra linker flags for linking shared libraries only

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to <[email protected]>.


嗨~,看的头痛,完整编译以便。

./configure --prefix=/opt/postgresql

checking for library containing readline... no
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

报错,没有readline

readline问题

请教一下apt老师

$ apt install postgresql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libsecret-1-0 libsecret-common python-asn1crypto python-backports.ssl-match-hostname python-cached-property python-certifi python-cffi-backend python-chardet
  python-cryptography python-dockerpty python-docopt python-enum34 python-funcsigs python-functools32 python-idna python-ipaddress python-jsonschema python-mock python-openssl
  python-pbr python-pkg-resources python-requests python-six python-texttable python-urllib3 python-websocket python-yaml
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common ssl-cert sysstat
Suggested packages:
  postgresql-doc locales-all postgresql-doc-10 libjson-perl openssl-blacklist isag
The following NEW packages will be installed:
  postgresql postgresql-10 postgresql-client-10 postgresql-client-common postgresql-common ssl-cert sysstat
0 upgraded, 7 newly installed, 0 to remove and 86 not upgraded.
Need to get 5,227 kB of archives.
After this operation, 20.5 MB of additional disk space will be used.
Do you want to continue? [Y/n] n
Abort.

没有看到有readline相关依赖,跳过把,不管了。
./configure --prefix=/opt/postgresql --without-readline

configure: using compiler=gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2
configure: using CPPFLAGS= -D_GNU_SOURCE 
configure: using LDFLAGS=  -Wl,--as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/dynloader/linux.c to src/backend/port/dynloader.c
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/backend/port/dynloader/linux.h to src/include/dynloader.h
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port

好像没有报错,开始编译

编译postgresql

make && make install
漫长的等待,终于编译好了,但是东西有点多,怎么分离出来有用的文件呢?

继续请教apt老师。

相关的头文件

$ dpkg -L libpq-dev | grep -F "/usr/include/postgresql"
/usr/include/postgresql
/usr/include/postgresql/internal
/usr/include/postgresql/internal/c.h
/usr/include/postgresql/internal/libpq
/usr/include/postgresql/internal/libpq/pqcomm.h
/usr/include/postgresql/internal/libpq-int.h
/usr/include/postgresql/internal/port.h
/usr/include/postgresql/internal/postgres_fe.h
/usr/include/postgresql/internal/pqexpbuffer.h
/usr/include/postgresql/libpq
/usr/include/postgresql/libpq/libpq-fs.h
/usr/include/postgresql/libpq-events.h
/usr/include/postgresql/libpq-fe.h
/usr/include/postgresql/pg_config.h
/usr/include/postgresql/pg_config_ext.h
/usr/include/postgresql/pg_config_manual.h
/usr/include/postgresql/pg_config_os.h
/usr/include/postgresql/postgres_ext.h

相关的库文件

$ dpkg -L libpq-dev | grep -F "/usr/lib/x86_64-linux-gnu"
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libpgcommon.a
/usr/lib/x86_64-linux-gnu/libpgfeutils.a
/usr/lib/x86_64-linux-gnu/libpgport.a
/usr/lib/x86_64-linux-gnu/libpq.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/libpq.pc
/usr/lib/x86_64-linux-gnu/libpq.so

库还好,可以分离出来,但是头文件有些麻烦,如果编译其他版本,头文件目录不一致,也是问题。

尝试单独编译libpq库

人家就是不支持,非得单独编译,嗨

头文件直接不分离,实在不行,开发时把真个头文件目录整个拷贝过去,多了也没有关系。

libpqxx

下载libpqxx

找到libpqxx与libpq的版本对应关系,
还是按照apt的版本对应关系。

$ dpkg -L libpqxx-dev | grep -F ".pc" | xargs cat        
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include

Name: libpqxx
Description: a C++ API to the PostgreSQL database management system.
Version: 4.0.1
Libs: -L${libdir} -L/usr/lib/x86_64-linux-gnu -lpqxx
Cflags: -I${includedir} -I/usr/include/postgresql

github源码地址:https://github.com/jtv/libpqxx

然并卵,libpqxx都没有这个4.01版本了,咋办。

选版本

libpqxx 从7.0.0版本,开始要求基于C++17,我这个的开发环境还是C++11
所以就用libpqxx的6.x.x的最后一个版本6.4.8好了。

https://github.com/jtv/libpqxx/archive/refs/tags/6.4.8.tar.gz

configure --help

# root @ ubuntu in ~/workspace/libpqxx-6.4.8 [9:19:51] 
$ ./configure --help
`configure' configures libpqxx 6.4.8 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking ...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc.  You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/libpqxx]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-dependency-tracking
                          do not reject slow dependency extractors
  --disable-dependency-tracking
                          speeds up one-time build
  --enable-silent-rules   less verbose build output (undo: "make V=1")
  --disable-silent-rules  verbose build output (undo: "make V=0")
  --enable-shared[=PKGS]  build shared libraries [default=no]
  --enable-static[=PKGS]  build static libraries [default=yes]
  --enable-fast-install[=PKGS]
                          optimize for fast installation [default=yes]
  --disable-libtool-lock  avoid locking (might break parallel builds)
  --enable-documentation  Generate documentation
  --enable-maintainer-mode
                          enable make rules and dependencies not useful (and
                          sometimes confusing) to the casual installer

  --enable-poll           System supports poll().

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-pic[=PKGS]       try to use only PIC/non-PIC objects [default=use
                          both]
  --with-aix-soname=aix|svr4|both
                          shared library versioning (aka "SONAME") variant to
                          provide on AIX, [default=aix].
  --with-gnu-ld           assume the C compiler uses GNU ld [default=no]
  --with-sysroot[=DIR]    Search for dependent libraries within DIR (or the
                          compiler's sysroot if not specified).
  --with-postgres-include=DIR
                          Use PostgreSQL includes from DIR. Defaults to
                          querying pg_config or pkg-config, whichever is
                          available.
  --with-postgres-lib=DIR Use PostgreSQL libraries from DIR. Defaults to
                          querying pg_config.

Some influential environment variables:
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CC          C compiler command
  CFLAGS      C compiler flags
  LT_SYS_LIBRARY_PATH
              User-defined run-time library search path.
  CPP         C preprocessor
  CXXCPP      C++ preprocessor
  DOXYGEN     Path to doxygen needed to build reference documentation
  HAVE_DOT    Variable used by doxygen to declare availibility of dot
  XMLTO       Path to xmlto needed to build tutorial documentation

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to <Jeroen T. Vermeulen>.

编译配置

./configure --prefix=/opt/libpqxx --with-postgres-include=/opt/postgresql/include --with-postgres-lib=/opt/postgresql/lib

$ ./configure  --prefix=/opt/libpqxx  --with-postgres-include=/opt/postgresql/include --with-postgres-lib=/opt/postgresql/lib
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ supports C++11 features with -std=c++11... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports the include directive... yes (GNU style)
checking whether make supports nested variables... yes
checking dependency style of g++ -std=c++11... gcc3
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ -std=c++11 accepts -g... (cached) yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -std=c++11 -E
checking for ld used by g++ -std=c++11... /usr/bin/ld -m elf_x86_64
checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ -std=c++11 linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ -std=c++11 option to produce PIC... -fPIC -DPIC
checking if g++ -std=c++11 PIC flag -fPIC -DPIC works... yes
checking if g++ -std=c++11 static flag -static works... yes
checking if g++ -std=c++11 supports -c -o file.o... yes
checking if g++ -std=c++11 supports -c -o file.o... (cached) yes
checking whether the g++ -std=c++11 linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether make sets $(MAKE)... (cached) yes
checking for mkdir... /bin/mkdir
checking for doxygen... no
checking for dot... no
checking for xmlto... no
checking whether to enable maintainer-specific portions of Makefiles... no
checking maintainer mode... 
checking audit... 
checking g++ visibility attribute... yes
checking whether the compiler supports function __attribute__((__const__))... yes
checking g++ deprecation attribute... yes
checking g++ pure attribute... yes
checking C++14 deprecation attribute... yes
checking for C++17 std::optional support... no
checking for experimental C++17 std::optional support... no
checking for C++17 charconv integer conversion... no
checking for C++17 charconv floating-point conversion... no
checking for poll(2)... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for pg_config... /usr/bin/pg_config
checking for pkg-config... /usr/bin/pkg-config
configure: using PostgreSQL headers at /opt/postgresql/include
configure: using PostgreSQL libraries at /opt/postgresql/lib
checking /opt/postgresql/include/libpq-fe.h usability... yes
checking /opt/postgresql/include/libpq-fe.h presence... yes
checking for /opt/postgresql/include/libpq-fe.h... yes
checking for ability to compile source files using libpq... yes
checking for PQexec in -lpq... yes
checking that type of libpq's Oid is as expected... yes
checking whether make sets $(MAKE)... (cached) yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config/Makefile
config.status: creating doc/Makefile
config.status: creating doc/Doxyfile
config.status: creating src/Makefile
config.status: creating test/Makefile
config.status: creating test/unit/Makefile
config.status: creating tools/Makefile
config.status: creating win32/Makefile
config.status: creating include/Makefile
config.status: creating include/pqxx/Makefile
config.status: creating libpqxx.pc
config.status: creating include/pqxx/config.h
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing configitems commands
Generating b'/root/workspace/libpqxx-6.4.8/include/pqxx/config-internal-autotools.h': 7 item(s).
Generating b'/root/workspace/libpqxx-6.4.8/include/pqxx/config-internal-compiler.h': 5 item(s).
Generating b'/root/workspace/libpqxx-6.4.8/include/pqxx/config-public-autotools.h': no items--skipping.
Generating b'/root/workspace/libpqxx-6.4.8/include/pqxx/config-public-compiler.h': 4 item(s).

好像没有问题,

编译

make && make install

报错

*****************************************************

xmlto not found.
Install it, or configure with --disable-documentation

*****************************************************
Makefile:508: recipe for target 'tutorial-stamp' failed
make[1]: *** [tutorial-stamp] Error 1
make[1]: Leaving directory '/root/workspace/libpqxx-6.4.8/doc'
Makefile:641: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

CNM,configure时不报错,非得在编译时报错。

再编译

./configure --prefix=/opt/libpqxx --with-postgres-include=/opt/postgresql/include --with-postgres-lib=/opt/postgresql/lib --disable-documentation
make && make install

# root @ ubuntu in /opt/libpqxx [9:32:58] 
$ tree -L 2
.
├── include
│   └── pqxx
└── lib
    ├── libpqxx.a
    ├── libpqxx.la
    └── pkgconfig

操了,没有动态库。make clean再来。

再再编译

make clean
./configure --prefix=/opt/libpqxx --with-postgres-include=/opt/postgresql/include --with-postgres-lib=/opt/postgresql/lib --disable-documentation --enable-shared=yes
make && make install

# root @ ubuntu in /opt/libpqxx [10:15:59] 
$ tree -L 2
.
├── include
│   └── pqxx
└── lib
    ├── libpqxx-6.4.so
    ├── libpqxx.a
    ├── libpqxx.la
    ├── libpqxx.so -> libpqxx-6.4.so
    └── pkgconfig

看看依赖

先配置一下环境变量
export LD_LIBRARY_PATH=/opt/postgresql/lib;$LD_LIBRARY_PATH

# root @ ubuntu in /opt/libpqxx/lib [10:22:26] 
$ ldd libpqxx.so 
	linux-vdso.so.1 (0x00007ffea9739000)
	libpq.so.5 => /opt/postgresql/lib/libpq.so.5 (0x00007f2579620000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f2579297000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2578ea6000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f2579acf000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2578c8e000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2578a6f000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f25786d1000)

好像没有问题,收工

你可能感兴趣的:(C/C++,ubuntu,linux,postgresql)