Skip to content

postgresql静态编译libpq--参考 #21

@jingjingxyk

Description

@jingjingxyk

libpq 静态编译 参考

libpq static compiler reference

# cpu_nums=`nproc 2> /dev/null || sysctl -n hw.ncpu`

cpu_nums=`grep "processor" /proc/cpuinfo | sort -u | wc -l`


wget https://ftp.postgresql.org/pub/source/v15.1/postgresql-15.1.tar.gz

mkdir -p pgsql 

tar --strip-components=1 -C pgsql -xf  postgresql-15.1.tar.gz

cd pgsql


sed -i "s/invokes exit'; exit 1;/invokes exit';/"  src/interfaces/libpq/Makefile

 # 替换指定行内容
sed -i "102c all: all-lib" src/interfaces/libpq/Makefile



export CPPFLAGS="-static -fPIE -fPIC -O2 -Wall "

./configure  --prefix=/usr/pgsql \
--enable-coverage=no \
--with-ssl=openssl  \
--with-readline \
--without-icu \
--without-ldap \
--without-libxml  \
--without-libxslt \
--with-includes="/usr/openssl/include/:/usr/zlib/include:/usr/include" \
--with-libraries="/usr/openssl/lib64:/usr/zlib/lib:/usr/lib"


make -C src/include install 
make -C  src/bin/pg_config install

make -C  src/common -j $cpu_nums all 
make -C  src/common install 

make -C  src/port -j $cpu_nums all 
make -C  src/port install 


make -C  src/backend/libpq -j $cpu_nums all 
make -C  src/backend/libpq install 

make -C src/interfaces/ecpg   -j $cpu_nums all-pgtypeslib-recurse all-ecpglib-recurse all-compatlib-recurse all-preproc-recurse
make -C src/interfaces/ecpg  install-pgtypeslib-recurse install-ecpglib-recurse install-compatlib-recurse install-preproc-recurse
            

make -C src/interfaces/libpq  -j $cpu_nums 

make -C src/interfaces/libpq  install 

编译PHP时指定库的位置

# 编译swoole扩展时需要下面两个参数
export LIBPQ_CFLAGS=$(pkg-config  --cflags --static      libpq)
export LIBPQ_LIBS=$(pkg-config  --libs  --static       libpq)


#编译 php时指定libpq
export CPPFLAGS=$(pkg-config  --cflags --static  libpq)
export LIBS=$(pkg-config  --libs --static   libpq)



编译PHP时指定PGSQL参数

    --enable-swoole  --enable-mysqlnd --enable-swoole-curl --enable-cares  --enable-swoole-pgsql  --with-brotli-dir=/usr/brotli  \
    --with-pgsql=/usr/pgsql \
    --with-pdo-pgsql=/usr/pgsql 

实验程序: https://github.com/jingjingxyk/swoole-cli/blob/5e27c2ca4b9ea672fef8b20157b21cb48fb5f6ea/prepare.php#L1148

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/extensionIssues related to extensions

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions