Updated on 2024-08-20 GMT+08:00

Development Process

To compile and develop source programs based on libpq, perform the following steps:
  • Decompress the GaussDB-Kernel_Database version number_OS version number_64bit_Libpq.tar.gz file. The required header file is stored in the include folder, and the lib folder contains the required libpq library file.

    In addition to libpq-fe.h, the include folder contains the header files postgres_ext.h, gs_thread.h, and gs_threadlocal.h by default. These three header files are the dependency files of libpq-fe.h.

  • Develop the source program testlibpq.c. The source code file needs to reference the header file provided by libpq.
    Example: #include <libpq-fe.h>
  • To compile the libpq source program by running gcc, use the -I directory option to provide the installation location of the header file. (Sometimes the compiler looks for the default directory, so this option can be ignored.) Example:
    gcc -I (Directory where the header file is located) -L (Directory where the libpq library is located) testlibpq.c -lpq
    Example: gcc -I $(GAUSSHOME)/include/libpq -L $(GAUSSHOME)/lib -lpq testlibpq.c -o testlibpq
  • If the makefile is used, add the following option to variables CPPFLAGS, LDFLAGS, and LIBS:
    CPPFLAGS += -I (Directory of the header file)
    LDFLAGS += -L (Directory of the libpq library)
    LIBS += -lpq
    Example:
    CPPFLAGS += -I$(GAUSSHOME)/include/libpq
    LDFLAGS += -L$(GAUSSHOME)/lib