[nginx] Windows下编译ngx_image_thumb
ngx_image_thumb模块主要功能是对请求的图片进行缩略/水印处理,支持文字水印和图片水印。
ngx_image_thumb支持Windows系统,不过要修改的代码太多了,包括Nginx本身,用VC++来编译,还是推荐使用Linux系统。
本篇文章只是对Windows下编译ngx_image_thumb模块的一次尝试,有些地方可能改的不对,最后没有编译成功!!
编译需求
在Microsoft Win32平台上构建nginx
你需要:
编译
- 下载ngx_image_thumb模块源码,解压到
$(ngixn_source_dir)/objs/lib
目录下。 打开
ngx_image_thumb
模块源码目录下的ngx_http_image_module.c
文件,将:#include <sys/stat.h>
- 改为:
#ifdef _WIN32 #include <direct.h> #include <io.h> #elif defined __linux__ #include <sys/stat.h> #endif
- 静态编译curl,生成
libcurl_a.lib
,如果使用静态库别忘了添加-DCURL_STATICLIB
参数。 使用的configure命令如下:
$ auto/configure --with-cc=cl --builddir=objs --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --with-cc-opt="-DFD_SETSIZE=1024 -Ie:/thirdparty_source/libgd-2.2.4/src -IE:/thirdparty/libcurl/include -Ilib/perl5/core_perl/CORE" --with-pcre=objs/lib/pcre-8.40 --with-zlib=objs/lib/zlib-1.2.11 --with-openssl=objs/lib/openssl-1.1.0d --with-select_module --with-http_ssl_module --with-http_image_filter_module --with-ld-opt="E:/thirdparty_source/gdbuild/libgd.lib E:/thirdparty/libcurl/lib/libcurl_a.lib" --add-module=objs/lib/ngx_image_thumb-master
也可以酌情使用下面的configure命令:
$ auto/configure --with-cc=cl --builddir=objs --prefix= --conf-path=conf/nginx.conf --pid-path=logs/nginx.pid --http-log-path=logs/access.log --error-log-path=logs/error.log --sbin-path=nginx.exe --http-client-body-temp-path=temp/client_body_temp --http-proxy-temp-path=temp/proxy_temp --http-fastcgi-temp-path=temp/fastcgi_temp --with-cc-opt="-DFD_SETSIZE=1024 -DCURL_STATICLIB -NODEFAULTLIB:"MSVCRT" -Ie:/thirdparty_source/libgd-2.2.4/src -IE:/thirdparty/libcurl/include" --with-pcre=objs/lib/pcre-8.40 --with-zlib=objs/lib/zlib-1.2.11 --with-openssl=objs/lib/openssl-1.1.0d --with-select_module --with-http_image_filter_module --with-ld-opt="E:/thirdparty_source/gdbuild/libgd.lib E:/thirdparty/libcurl/lib/libcurl_a.lib" --add-module=objs/lib/ngx_image_thumb-master
遇到的错误和解决方法
- 如果编译时出现
C2071错误
或ngx_image_conf_t
结构体相关错误,则去掉源码中中的中文注释。 warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。
警告,则需使用Visual Studio将编码格式改变为【简体中文(GB2312)- 代码页936】
或【Unicode】
。出现
“_mkdir”: 实参太多
错误// 将下面一行 if(mkdir(dirname,0777)==-1) // 替换为 if(mkdir(dirname)==-1)
warning C4996
导致无法编译完成编译, 打开objs/Makefile
文件,将下面一行CFLAGS = -O2 -W4 -WX -nologo -MT -Zi -DFD_SETSIZE=1024 -Ie:/thirdparty_source/libgd-2.2.4/src -IE:/thirdparty/libcurl/include
把/W4
改成/W3
,并且去掉/WX
。
warning LNK4098: 默认库“MSVCRT”与其他库的使用冲突;请使用 /NODEFAULTLIB:library
,则使用-NODEFAULTLIB:"MSVCRT"
忽略指定的库。