mysql - 使用依赖库编译nginx模块

标签 mysql c nginx

我已经按照这里的教程成功构建了一个简单的 nginx 模块:https://github.com/perusio/nginx-hello-world-module

我可以毫无问题地构建和运行该代码,并且它可以正常运行。

我现在想将 MySQL 的依赖项添加到简单的 nginx 模块,所以我使用了 MySQL C 连接器 http://dev.mysql.com/doc/refman/5.6/en/c-api-building-clients.html .

你能写的最简单的程序是这样的(取自 http://zetcode.com/db/mysqlc/ ):

mysql_test.c

#include <my_global.h>
#include <mysql.h>

int main(int argc, char **argv) 
{
  printf("MySQL client version: %s\n", mysql_get_client_info());  
  exit(0);
}

然后你像这样编译:

$ gcc mysql_test.c -o mysql_test  `mysql_config --cflags --libs`

这很好用。

现在,当我尝试将两个头文件 my_global.hmysql.h 包含在我的简单 nginx hello-world 模块中时,我需要一种方法来指定那些构建标志,否则它不会找到那些头文件。目前,当我运行 make 时,在成功构建所有其他模块后,我现在得到:

cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g   -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/mail \
        -o objs/addon/nginx-hello-world-module/ngx_http_hello_world_module.o \
        /vagrant/nginx-hello-world-module/ngx_http_hello_world_module.c
/vagrant/nginx-hello-world-module/ngx_http_hello_world_module.c:33:23: fatal error: my_global.h: No such file or directory
 #include <my_global.h>
                       ^
compilation terminated.
make[1]: *** [objs/addon/nginx-hello-world-module/ngx_http_hello_world_module.o] Error 1
make[1]: Leaving directory `/vagrant/nginx'
make: *** [build] Error 2

我的问题是:如何让 nginx 在构建我的模块时包含这些构建标志?

我还没有找到任何关于使用 Nginx 构建依赖项的信息。

谢谢!

最佳答案

Compilation Controls

--with-cc-opt=parameters sets additional parameters that will be added to the CFLAGS variable.

--with-ld-opt=parameters sets additional parameters that will be used during linking.

Source

对于 MySQL 连接器 C,它将类似于:

--with-cc-opt="-I/usr/include/mysql"
--with-ld-opt="-L/usr/lib64/mysql"

在你模块的 config 文件中:

CORE_LIBS="$CORE_LIBS -lmysqlclient"

在编译期间,它可能还会提示 _GNU_SOURCE 被重新定义,如果您使用 -Werror 而没有实现解决方法,它将失败。

关于mysql - 使用依赖库编译nginx模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32991429/

相关文章:

java - 使用 nginx 服务器作为 glassfish 服务器的代理来加载静态内容

nginx - 当配置中已经存在奇迹 block 时,如何为 kibana4 配置 Nginx 服务器 block

SQL:ORDER BY 两列混合,不基于优先级

phpMyAdmin 4.6.2 token 不匹配

MySQL 的联合和排序通过帮助

php - 如何修改此 PHP 代码以返回嵌套结果

C,在大小为 15 的无符号整数数组的空间中存储长度 <=60 的字符串

c - 使用 libgda-ui 调用 row-activated

c++ - 在具有多个接口(interface)的linux主机上接收多播

http - NGINX 根据 header 的值设置 cookie