Configure the msvc command line Environment (continued) -- compile the msvc compilation script

Source: Internet
Author: User
Configure the msvc command line Environment (continued) -- compile the msvc compilation script

After configuring the msvc command line environment (see 《Configure the msvc command line Environment), You can use the command line to compile small sample programs.
If you need to publish the compilation script to others or test multiple VC versions, you also need some tips.

Recall the following requirements:
1. Release the compilation script to others.
Minimize the dependency on the customer's machine configuration (mainly environment variables.

2. Test multiple VC versions
Avoid using global (system or current user) environment variables on the local machine as much as possible, because switching is inconvenient.

3. write scripts for yourself.Convenient
Because the purpose of using command line isConvenient.

If it is not convenient enough, it is better to use ide. It is more secure.
-- Correctly compiled workspace files, solution files, project files, and project files are certainly usable for customers who have installed VC.
(Correct means that it does not depend on any settings on the local machine, such as the global search path .)

I. For vc8 and vc9

Write the following script:

"Call % vSxxComntools % vSVars32.bat ".
Rem executes the corresponding CL command.

In this way, the above three requirements can be met:
1. There must be correct vsxxcomntools variables on the client-unless the corresponding VC version is not installed.
2. Execute the CL command.SeparatePut it in a script (assumingCpl. bat) To execute the same compilation process of vc8 and 9.

For different VC versions, Run "Call % vSxxComntools % vSVars32.bat ", for example:
-------- Vc8.bat --------
Call "% vs80comntools % vsvars32.bat"
Call Cpl. bat

-------- Vc9.bat --------
Call "% vs90comntools % vsvars32.bat"
Call Cpl. bat

3. The compilation process is in a separate Cpl. bat, which facilitates management and maintenance.

 

 

II. For vc6

Ii. 1. Use DSW and DSP files

That is, use the workspace files and engineering files provided by IDE.
This is the safest thing-as long as the customer installs vc6, it can be used whether or not any environment variables are set.

2. Assume that the customer has the correct system or the current user's environment variables.

You don't need to set anything else. You can directly use the same compilation script as vc8 or 9, for example:
-------- Vc6.bat --------
Call Cpl. bat

Assume thatNot validHour:
1. The customer re-installs vc6
2. manually add environment variables. For more information, see 《Configure the msvc command line Environment.

There is another defect, if:
Ii. 2.1. the customer has installed Multiple VC versions
Ii. 2.2. environment variables of the system or the current user are set for a non-vc6 version.
Ii. 2.3. The environment variable of vc6 exists and is after the environment variable of another VC version

Then vc6.bat does not actually use vc6 for compilation,AnotherVC version.

Ii. 3. Use vcvars32.bat (for vc6)

Ii. 3.1 Use the msdevdir variable

After "register environment variable" is selected during vc6 installation, msdevdir is set in addition to the corresponding path, include, and Lib.
You can use it as follows:
-------- Vc6.bat --------
Call "% msdevdir %/../../Vc98/bin/vcvars32.bat"
Call Cpl. bat

Note the following two points:
1. The client is still dependent on the correct environment variables for vc6.
Unlike "II. 2.2", there will be no defect of "II. 2.3.

2. msdevdir and vcvars32.batRelative Position, Not necessarily as written above!
When installing vc6, you are asked to select a common folder first.
After the installation is complete, its relationship with msdevdir is:
Common/msdev98

Then, the user can select the location of the VC. It can be different from the above.

Ii. 3.2 use vcvars32.bat directly

For example:
Call vcvars32.bat
Call Cpl. bat

Comparison with 2.2:
1. When you install vc6, select "register environment variable"
Then,"Prefix/Microsoft Visual Studio/vc98/bin.
Vcvars32.bat is also in this directory, and the execution is successful.

At the same time, even in this case (the customer's necessary environment variables), calling vcvars32.bat again is not necessarily redundant.
Because this can avoid the defects mentioned in "2.2.2", it must be compiled using vc6 instead of other versions of VC.

2. The customer did not select "register environment variable" when installing vc6"
Compared with 2.2.2, the customer needs to do less work:Prefix/Microsoft Visual Studio/vc98/bin Add"Path.
You do not need to add 2 to 5 other variables.

This should be the best way to not use IDE.

Iii. Summary

1. SetTotal compilation LogicWrite it in a separate script, suchCpl. bat.

2. For vc8 and 9, use the vsxcomntools variable as follows:
-------- Vc8.bat --------
Call "% vS80 comntools % vSVars32.bat"
Call Cpl. bat

-------- Vc9.bat --------
Call "% vS90 comntools % vSVars32.bat"
Call Cpl. bat

Note:: The above is vs rather than VC.

3. For vc6

3.1 Use DSW and DSP files

This is the safest way.
However, the CPl. BAT file that has been written cannot be used and must be maintained independently.

3.2 directly use vcvars32.bat

-------- Vc6.bat --------
Call vcvars32.bat
Call Cpl. bat

The advantage is that you can onlyMaintenance separatelyCpl. bat, the client can also correctly compile multiple VC versions -- if the environment variable of his vc6 is correct.
If it is incorrect, the customer needs to do little work, just add an environment variable.

Iv. Example

Use 《Predefine _ msc_ver macroTo compile an editing script using multiple VC versions. PointThisDownload the packaging code.

1. Source Code
-------- _ Msc_ver/_ msc_ver.cpp --------
For more information, see 《Predefine _ msc_ver macroOrPackaging code.

2. General Compilation Logic
-------- _ Msc_ver/VC/Cpl. Bat --------
Cl ../_ msc_ver.cpp/W4
Pause

3. Compile a simple call script for different VC versions
-------- _ Msc_ver/vc6/vc6.bat --------
Call vcvars32.bat
Call ../VC/Cpl. bat

-------- _ Msc_ver/vc8/vc8.bat --------
Call "% vs80comntools % vsvars32.bat"
Call ../VC/Cpl. bat

-------- _ Msc_ver/vc9/vc9.bat --------
Call "% vs90comntools % vsvars32.bat"
Call ../VC/Cpl. bat

Supplement:

-- AboutScriptAndBatch Processing.
All the scripts mentioned in this article are bat batch files under DOS, which are very functional.Weak.
This is just a convenient example.Using multiple VC versionsThat is, vc6.bat, vc8.bat, and vc9.bat in summary.
They first use the corresponding vcvars32.bat to register the local environment of the process, and then call Cpl. bat.

Actually,Cpl. bat is the logic of compilation.If the DOS bat batch processing cannot complete its functions, you can also use other tools, such as makefile.
Therefore, this article always says "compile scripts" instead of "compile batch processing", although the compilation script in this article is a simple (not including some logic) Batch Processing file.

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.