Compile NGINX with Visual Studio -
i have 2 questions regarding nginx:
is there 1 had compile nginx visual studio? want create vs9 project compiling nginx.
it's veritable need, there way compile nginx lib or dll?
i finished building visual studio 2010 project nginx. process wasn't entirely straight-forward, attempt detail i've learned. several-hour several day process, depending on experience.
step 1: must first follow guide building nginx on windows. not builds nginx, creates .c , .h files use when creating visual studio project. won't work without these files. (for more information, see here.)
if less experienced unix me, guide above leaves unanswered questions. i'll first flesh out guide tips of own, , later, tell more creating project visual studio.
part i: compiling nginx windows using msys
first, follow steps given above. install msys, strawberry perl, mercurial, , download pcre, zlib, , openssl libraries. follow these steps:
1) open command prompt administrator. run visual studio vc\vcvarsall.bat file set environment variables use vc compiler. paths different, command used was:
"c:\program files\microsoft visual studio 10.0\vc\vcvarsall.bat"
i found though strawberry perl added 3 paths (which can verify examining path variable), still using wrong perl.
2) launch msys running msys.bat. me, msys installed inside of mingw directory, path was: c:\mingw\msys\1.0\msys.bat
if successful, should see in green: jensenv@avwma047lb ~ (except username@networkaddress instead) in window called mingw32:~
you might wondering 'home folder is. it's under msys\1.0\home. on system, it's here: c:\mingw\msys\1.0\home\jensenv
if "ls" or "dir" directory you're in initially.
3) assuming installed mercurial instructed above, should able check out ngynx source: hg clone http://hg.nginx.org/nginx
this go directory mentioned above.
4) need make sure version of perl being used strawberry perl, not version comes msys. type: perl
if "/bin/perl.exe" that's wrong perl , need fixing paths. can either mess (as did, unsuccessfully) or can disable version of perl comes msys. renamed perl.exe perl_unused.exe in msys install:
c:\mingw\msys\1.0\bin
whatever do, make sure "which perl" shows path strawberry perl before proceeding.
5) renamed "link.exe" in msys\1.0\bin directory: c:\mingw\msys\1.0\bin it's unused. (i.e. rename "link_unused.exe")
i believe because, in step 1 above, "vcvarsall.bat" set use microsoft c's compiler/linker, in step 2, linker changed use msys 1 instead. need use microsoft one.
to verify renaming "link_unused.exe" successful, type: link , ensure points visual studio 10 link, not link.exe came msys.
6) first "cd nginx" create objs/lib folder tree inside of nginx folder. untar/unzip pcre, zlib, , openssl in here mentioned in guide.
7) while current directory still nginx, run nginx's autoconfigure script, first modify command below change paths sopenssl, pcre, , zlib correct installed in objs/lib (your version numbers may different). command used was:
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 \ --with-pcre=objs/lib/pcre-8.33 \ --with-zlib=objs/lib/zlib-1.2.8 \ --with-openssl=objs/lib/openssl-1.0.1f \ --with-select_module --with-http_ssl_module --with-ipv6
if want change configuration options, time. these options affect generated .c , .h files use later in creating visual studio project, , trust me, don't want have redo later when realize need different options.
7) make it.
nmake -f objs/makefile
if successful, freshly compiled nginx.exe should inside home\yourusername\nginx\objs folder. i.e. like: c:\mingw\msys\1.0\home\jensenv\nginx\objs
in addition, these files in same folder nginx.exe: ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_pch.c
you use these in creating visual studio project.
8) have beer.
**
part ii: creating visual studio nginx project
**
create empty visual studio project command line application. save project inside nginx folder (root level). note before step can move nginx folder outside of msys wherever want keep it.
1) go properties -> vc++ directories , add these include directories:
$(msbuildprojectdirectory)\src\core $(msbuildprojectdirectory)\src\event $(msbuildprojectdirectory)\src\event\modules $(msbuildprojectdirectory)\src\http $(msbuildprojectdirectory)\src\http\modules $(msbuildprojectdirectory)\src\http\modules\perl $(msbuildprojectdirectory)\src\mail $(msbuildprojectdirectory)\src\misc $(msbuildprojectdirectory)\src\mysql $(msbuildprojectdirectory)\src\os $(msbuildprojectdirectory)\objs $(msbuildprojectdirectory)\src\os\win32 $(msbuildprojectdirectory)\objs\lib\openssl\ssl\include $(msbuildprojectdirectory)\objs\lib\zlib $(msbuildprojectdirectory)\objs\lib\pcre
note: before step went objs/lib , removed version numbers zlib, pcre, , ssl folders. either should to, or should modify paths above match installed versions. removed version numbers can update newer versions of these libraries in future without breaking project.
click on "macros >>" button , verify msbuildprojectdirectory path path nginx folder.
2) likewise add these paths library directories:
$(msbuildprojectdirectory)\objs\lib\openssl\ssl\lib\ $(msbuildprojectdirectory)\objs\lib\pcre\ $(msbuildprojectdirectory)\objs\lib\zlib\
again, modify these paths include version numbers if objs/lib folder's contents still have version numbers.
3) change these project properties follows:
c/c++ general: set "treat warnings errors" no (wx-) preprocessor: add these preprocessor definitions: win32 ngx_win32 ngx_mail_ssl no_sys_types_h fd_setsize=1024
linker: input: add following additional dependencies: ws2_32.lib pcre.lib ssleay32.lib libeay32.lib crypt32.lib zlib.lib
4) close visual studio solution. open project file (ends in .vcxproj) text editor, such notepad++. (make backup copy of first, in case goes wrong.) open nginx\objs\makefile text editor.
in makefile, not far top, you'll see section starts this:
objs/nginx.exe: objs/src/core/nginx.obj \ objs/src/core/ngx_log.obj \ objs/src/core/ngx_palloc.obj \ objs/src/core/ngx_array.obj \ .... objs/ngx_modules.obj \ objs/nginx.res \ objs/lib/pcre-8.33/pcre.lib \ objs/lib/zlib-1.2.8/zlib.lib $(link) @<<
likewise, in visual studio file, if you've added source code (add files want prior step, can see i'm talking about) you'll see this:
create new document containing .obj files makefile. use search & replace in text editor modify them match format of visual studio project file instead (so ending in .c /> instead of .obj \, , starting
also don't forget change forward slashes backslashes. don't include zlib.lib or pcre.lib lines. forget if should include nginx.res. (probably not.)
once you're sure format right, save visual studio project , try opening it. if files makefile show in project, did correctly.
5) remember special .c , .h files nginx created when built exe? want add them project now, too. add these guys:
ngx_modules.c ngx_pch.c
6) you're ready compile!
i've forgotten along way, might still have linker or compile errors fix, should give start!
note: if want change options included in nginx, you'll have new auto/configure in part above, new nmake, , include additional source code in visual studio project, , use newly generated ngx_modules.c , ngx_pch.c files in visual studio project.
Comments
Post a Comment