如何在Apache 2.2.17 for Win32中静态编译模块

在apache.exe中静态编译模块可能吗?

在Linux和Mac端,我能够build立一个包含所有deps(apr,apr-util,pcre)和我需要的模块的apache exec(httpd),但是在Windows中,我只能build立一个apache.exe独立(这只会支持apr.dll,apr-util.dll和其他deps)没有模块。 因此,例如,我无法在httpd.conf文件中使用Order指令,因为所需的模块不包含在apache.exe中。

我修改了很多包含httpd.mak文件的mak文件,以这种方式使用link.exe构buildapache.exe:

 link.exe Release \ main.obj \ 
发行\ httpd.res \ 
 srclib \ apr \ Release \ libapr.lib \ 
 srclib \ pcre \ Release \ pcre.lib \ 
 srclib \ apr-iconv \ Release \ libapriconv.lib \ 
发行\ my_modules.lib \ 
发布\ libhttpd.lib 

每个.lib文件都具有与lib.exe静态构build的所有obj文件

以这种方式构build“my_modules.lib”似乎被忽略,所有obj模块文件都不包含在apache.exe中(例如mod_authn_file.obj,mod_expires,mod_actions等等)。

如果我这样在构build过程中明确添加obj文件:

 link.exe Release \ main.obj \ 
发行\ httpd.res \ 
 srclib \ apr \ Release \ libapr.lib \ 
 srclib \ pcre \ Release \ pcre.lib \ 
 srclib \ apr-iconv \ Release \ libapriconv.lib \ 
发行\ libhttpd.lib \ 
 modules \ Release \ mod_authn_file.obj \ 
 modules \ Release \ mod_expires.obj \ 
 modules \ Release \ mod_actions.obj \ 
 ......(其他对象模块) 

apache.exe的大小增长,但如果我使用命令apache.exe -M来查看加载的模块,我只find:

 core_module(静态) 
 win32_module(静态) 
 mpm_winnt_module(静态) 
 http:模块(静态) 
 so_module(静态) 

[这是所有不包含在my_modules.lib中的模块]

使用Dependency Walker我可以看到apache.exe中的所有模块:

 actions_module
 alias_module
 _ap_get_server_built @ 0
 auth_basic_module
 authn_default_module
 authn_file_module
 authz_default_module
 authz_groupfile_module
 authz_host_module
 authz_user_module
 cgi_module
 dir_module
 expires_module
 filter_module
 http_module
 log_config_module
 mime_module
 mpm_winnt_module
 setenvif_module
 so_module
 status_module
 version_module
 win32_module

看起来这些模块已经链接,但是它们没有启用…

我希望有人能帮助我。

我解决了它…

我用这种方法修改os / win32 /文件夹中的modules.c文件:

 #undef AP_DECLARE_EXPORT
 #define AP_DECLARE_STATIC

 #定义CORE_PRIVATE
 #include“httpd.h”
 #include“http_config.h”

外部模块core_module;
外部模块win32_module;
外部模块mpm_winnt_module;
 extern模块http_module;
外部模块so_module;
外部模块authn_file_module;
 extern module authn_default_module;
 extern模块authz_host_module;
 extern模块authz_groupfile_module;
 extern模块authz_user_module;
 extern模块authz_default_module;
 extern模块auth_basic_module;
外部模块filter_module;
外部模块deflate_module;
外部模块log_config_module;
 extern模块expires_module;
外部模块setenvif_module;
外部模块version_module;
外部模块ssl_module;
外部模块mime_module;
外部模块status_module;
 extern模块cgi_module;
外部模块dir_module;
外部模块actions_module;
 extern模块alias_module;

 AP_DECLARE_DATA模块* ap_prelinked_modules [] = {
   &core_module,
   &win32_module,
   &mpm_winnt_module,
   &http_module,
   &so_module,
   &authn_file_module,
   &authn_default_module,
   &authz_host_module,
   &authz_groupfile_module,
   &authz_user_module,
   &authz_default_module,
   &auth_basic_module,
   &filter_module,
   &deflate_module,
   &log_config_module,
   &expires_module,
   &setenvif_module,
   &version_module,
   &ssl_module,
   &mime_module,
   &status_module,
   &cgi_module,
   &dir_module,
   &actions_module,
   &alias_module,
  空值
 };

 ap_module_symbol_t ap_prelinked_module_symbols [] = {
   {“core_module”,&core_module},
   {“win32_module”,&win32_module},
   {“mpm_winnt_module”,&mpm_winnt_module},
   {“http_module”,&http_module},
   {“so_module”,&so_module},
   {“authn_file_module”,&authn_file_module},
   {“authn_default_module”,&authn_default_module},
   {“authz_host_module”,&authz_host_module},
   {“authz_groupfile_module”,&authz_groupfile_module},
   {“authz_user_module”,&authz_user_module},
   {“authz_default_module”,&authz_default_module},
   {“auth_basic_module”,&auth_basic_module},
   {“filter_module”,&filter_module},
   {“deflate_module”,&deflate_module},
   {“log_config_module”,&log_config_module},
   {“expires_module”,&expires_module},
   {“setenvif_module”,&setenvif_module},
   {“version_module”,&version_module},
   {“ssl_module”,&ssl_module},
   {“mime_module”,&mime_module},
   {“status_module”,&status_module},
   {“cgi_module”,&cgi_module},
   {“dir_module”,&dir_module},
   {“actions_module”,&actions_module},
   {“alias_module”,&alias_module},
   {NULL,NULL}
 };

 AP_DECLARE_DATA模块* ap_preloaded_modules [] = {
   &core_module,
   &win32_module,
   &mpm_winnt_module,
   &http_module,
   &so_module,
   &authn_file_module,
   &authn_default_module,
   &authz_host_module,
   &authz_groupfile_module,
   &authz_user_module,
   &authz_default_module,
   &auth_basic_module,
   &filter_module,
   &deflate_module,
   &log_config_module,
   &expires_module,
   &setenvif_module,
   &version_module,
   &ssl_module,
   &mime_module,
   &status_module,
   &cgi_module,
   &dir_module,
   &actions_module,
   &alias_module,
  空值
 };

然后我用这个命令重新编译modules.obj文件:

 C:\ Documents and Settings \ sessa \ Desktop \ httpd-2.2.17-win32-src \ httpd-2.2.17_21>
 cl.exe / nologo / MT / W3 / Zi / O2 / Oy- / I“./srclib/pcre”/ I“./include”/ I“./srclib/apr/include”/ I“./srclib/ apr-util / include“/ I”./server/mpm/winnt“/ I”./modules/http“/ I”./modules/proxy“/ I”./modules/mappers“/ I”./server “/I"./modules/generators”/ I“./modules/filters”/ D“NDEBUG”/ D“WIN32”/ D“_CONSOLE”/ D“APR_DECLARE_STATIC”/ D“AP_DECLARE_STATIC”/ D“API_DECLARE_STATIC”/ D“APU_DECLARE_STATIC”/ D“PCRE_STATIC”/ Fo“Release \\”/ Fd“Release \ modules_sessa”/ FD / c ./os/win32/modules.c

然后我重buildapache.exe并执行apache.exe -M:

加载模块:
  core_module(静态)
  win32_module(静态)
  mpm_winnt_module(静态)
  http_module(静态)
  so_module(静态)
  authn_file_module(静态)
  authn_default_module(静态)
  authz_host_module(静态)
  authz_groupfile_module(静态)
  authz_user_module(静态)
  authz_default_module(静态)
  auth_basic_module(静态)
  filter_module(静态)
  log_config_module(静态)
  expires_module(静态)
  setenvif_module(静态)
  version_module(静态)
  deflate_module(静态)
  ssl_module(静态)
  mime_module(静态)
  status_module(静态)
  cgi_module(静态)
  dir_module(静态)
  actions_module(静态)
  alias_module(静态)
语法OK

所以这样我就编译了一个静态的apache 2.2.17 for win32!