Run nmake to compile Vc in Windows

Source: Internet
Author: User

My gdal compilation is completed by running nmake in the prompt windows provided by vs2012. But what if I want to automate compilation and put it in Jenkins? First of all, there is no vs2012 project, and you do not want to generate one. It is a circle. In fact, you only need to solve one problem. Why can't you run nmake in a common Windows Command Prompt window.

That's because the nmke path does not load the environment variable. Well, manually add it to the path. Continue, because nmake eventually reads the makefile. VC file, and the generated CL and link commands. cl need to include the directory path. To add the directory, link must depend on the library path and add it. This is why nmake is run in the prompt windows provided by vs2012, because it is all done for you. To compile a 64-bit program, you also need to open vs2012 Prompt Windows dedicated to 64bit, because these paths are slightly changed.

What should I do after the theory is finished? As a guide, I recommend reading an article: http://bojan-komazec.blogspot.com/2011/10/nmake-and-its-environment.html

This article is very good and patiently explains the reasons why I didn't work. Then, the author's own bat file is provided. After the BAT file is run, the correct environment variable is set. However, he does not support vs2012. I will take it and modify it. The following is my vc_env.bat file:

@rem modifed by Dean Chen to only support Visual Studio 2012 x86/x64 tools, initial version from http://bojan-komazec.blogspot.com/2011/10/nmake-and-its-environment.html @echo off@if "%1"=="x86" goto set_x86@if "%1"=="x64" goto set_x64@if "%1"=="" goto error:set_x86@echo Setting environment for using Microsoft Visual Studio 2012 x86 tools.set INCLUDE=^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE;^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\ATLMFC\INCLUDE;^C:\Program Files (x86)\Windows Kits\8.0\include\shared;^C:\Program Files (x86)\Windows Kits\8.0\include\um;^C:\Program Files (x86)\Windows Kits\8.0\include\winrt;set LIB=^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\LIB;^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\ATLMFC\LIB;^C:\Program Files (x86)\Windows Kits\8.0\lib\win8\um\x86;set PATH=^%SystemRoot%\system32;^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin;^C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE;^C:\Program Files (x86)\Windows Kits\8.0\bin\x86;goto test_bin_locations:set_x64@echo Setting environment for using Microsoft Visual Studio 2012 x64 tools.set INCLUDE=^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE;^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\ATLMFC\INCLUDE;^C:\Program Files (x86)\Windows Kits\8.0\include\shared;^C:\Program Files (x86)\Windows Kits\8.0\include\um;^C:\Program Files (x86)\Windows Kits\8.0\include\winrt;set LIB=^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\LIB\amd64;^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\lib\amd64;^C:\Program Files (x86)\Windows Kits\8.0\lib\win8\um\x64;set PATH=^%SystemRoot%\system32;^C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64;^C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE;^C:\Program Files (x86)\Windows Kits\8.0\bin\x64;goto test_bin_locations:test_bin_locations@echo onwhere nmakewhere cl.exewhere link.exe@echo offgoto:eof:error@echo Usage: setenv.bat [x86^|x64]goto:eof

Note that nothing remains unchanged. I made some supplements. For example, the environment variable setting of the original author does not support Windows kits. I added it. Otherwise, an error is reported during gdal compilation, and a program cannot be found.

How can we solve this problem? It is the right solution to teach people to fish.

1. Open the prompt windows provided by vs2012 and use env to display all environment variables

2. Use the everything search program to find the path and add it to the PATH variable.

3. What about vs 2012? You can use an existing vs2012 project to find the missing header file. Third, it is generally not needed, but it is suitable for programmers who cannot leave IDE.

Now, how can we compile it in Jenkins? It's easy to use & to write a line. On the Jenkins build Projecte configuration page, add the previous configuration.

Execute windows batch command:

c:\\vc_env.bat x86 & cd codes\\deps\\gdal\\gdal_1.8_rtc & nmake -f makefile.vc

The original author has an article about how to use Namek to create a VC project. We recommend that you read the following:

Http://bojan-komazec.blogspot.com/2011/10/how-to-use-nmake-and-makefile.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.