【问题标题】:Apache httpd custom module libpq PostgreSQL connectionApache httpd 自定义模块 libpq PostgreSQL 连接
【发布时间】:2021-02-22 19:44:36
【问题描述】:

我正在尝试为 apache httpd 创建新模块,以根据来自 PostgreSQL 的 SQL 查询修改请求标头。

我曾尝试使用libpq-fe.h 来做到这一点。我已经使用yum install postgresql-devel 安装了postgresql-devel

我尝试过简单地使用 libpq:

#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "apr_dbd.h"
#include "mod_dbd.h"
#include "libpq-fe.h"


/* The sample content handler */
static int my_apache2_module_handler(request_rec *r)
{
    int lib_ver = PQlibVersion();
    ...
}

包含本身工作得很好,但是当我调用PQlibVersion() 函数时,我得到undefined symbol: PQlibVersion 错误。

我已尝试将 libpq 库复制到 /usr/include/httpd

我尝试使用LoadFile /usr/include/libpq-fe.h 加载库,但我得到/usr/include/libpq-fe.h: invalid ELF header

我需要重新编译 httpd 才能使用 tihs 库吗? PostgreSQL 连接有 httpd 库吗?

版本

PostgreSQL - 13.1

httpd - 2.4.37

libpq-devel - 12.5

更新

问题解决了。编译模块并为链接器提供 libpq 库的路径。另外,我添加了LoadFile /usr/lib64/libpq.so。我已经加载了.h 文件而不是.so 文件

【问题讨论】:

  • 你是如何告诉链接器链接到库的?
  • 谢谢,我忘记添加这个标志了。我添加了 -I 标志并运行了这个命令apxs -i -a -c mod_my_apache2_module.c -I /usr/pgsql-10/include,但现在我得到了mod_my_apache2_module.c:5:10: fatal error: libpq-fe.h: No such file or directory
  • OK 编译成功,我不得不更改标志顺序。但仍然得到原来的错误 - undefined symbol: PQlibVersion
  • 我尝试添加LoadFile /usr/pgsql-10/include/libpq-fe.h,但得到/usr/pgsql-10/include/libpq-fe.h: invalid ELF header 错误

标签: c postgresql apache


【解决方案1】:

只包含头文件是不够的,还得链接-l pq

使用-w all 并在编译和链接时查看警告。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2011-11-12
    • 2022-01-09
    • 2018-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多