Learning windows programming (2) -- prepare the environment without using IDE

Source: Internet
Author: User


In order to solve the problem, we need to break away from the IDE and ensure that every character is produced by thinking. In fact, we are not isolated from the IDE environment, you can better understand how each step is executed. The other advantage of IDE is that when you select a project and create a project, when you want to write a small test program, you do not need to open the VC, but write it directly in a text editor. Compile and run the program in the command line to see the result, it saves a lot of time.

Next, let's take a look at how to work out of the IDE.

1. on the premise that VC6 is installed, win + R, Enter cmd, and try the "nmake" command in the command line window that appears. If the command can be executed, you can perform the following operations. Otherwise, you need to set the environment variable according to the operation in step 2. If you have studied java or linux, you should be familiar with this.

2. In the cmd environment, you can use the echo % path % command to display the environment variable path in the current system. Alternatively, right-click "my computer" and select the "Advanced" Tab in the displayed "properties" dialog box. In "Environment Variables, find "path" in "user environment variables" and click Modify.

3. find the place where nmake.exe is located on your computer, and enter "d: Program FilesMicrosoft Visual StudioVC98BinNMAKE. EXE ", add this path to the path, because it is possible that the environment variables on your computer include the path of Platform SDK and other versions of VS, so which one do you want to use, put it at the beginning.
In this directory, you can also see other exe programs, some of which will be used later, such as CL. EXE and LINK..

4. After setting, restart cmd and run the echo % path % command to check whether the path has been added and whether it is at the beginning.
Perform Step 1 to check whether the nmake command can be executed.
The final result is:

1 D:> nmake2 3 Microsoft (R) Program Maintenance Utility Version 6.00.8168.04 Copyright (C) Microsoft Corp 1988-1998. all rights reserved.5 6 NMAKE: fatal error U1064: MAKEFILE not found and no target specified7 Stop.5. after NMAKE is set. after the EXE is successful, you can try to execute CL. EXE command. If a mspdb60.dll cannot be found, you don't need to worry about it. It is because there is another path not set.
Find the mspdb60.dll file on your computer. The path on my computer is d: Program FilesMicrosoft Visual StudioCommonMSDev98BinMSPDB60. DLL ", you can see from the path name, this should be a public file belonging to the Dev environment, here we do not care about its specific, directly add the path to the path, after adding the path, the two paths must be separated by semicolons.

6. Similarly, set path, restart the cmd window, echo to check whether the setting is successful, and then execute the cl and link commands.
The result is as follows:

1 D:> cl2 Microsoft (R) 32-bit C/C ++ Optimizing Compiler Version 12.00.8168 for 80x863 Copyright (C) Microsoft Corp 1984-1998. all rights reserved.4 5 usage: cl [option...] filename... [/link linkoption...] link
1 D:> link 2 Microsoft (R) Incremental Linker Version 6.00.8168 3 Copyright (C) Microsoft Corp 1992-1998. all rights reserved. 4 5 usage: LINK [options] [files] [@ commandfile] 6 7 options: 8 9/ALIGN: #10/BASE: {address | @ filename, key} 11/COMMENT: comment12/DEBUG13/DEBUGTYPE: {CV | COFF} 14/DEF: filename15/DEFAULTLIB: library16/DELAY: {NOBIND | UNLOAD} 17/DELAYLOAD: dll18/DLL19/DRIVER [: {UPONLY | WDM}] 20/ENTRY: symbol21/EXETYPE: DYNAMIC22/EXPORT: symbol23/FIXED [: NO] 24/FORCE [: {MULTIPLE | UNRESOLVED}] 25/GPSIZE: #26/HEAP: reserve [, commit] 27/IMPLIB: filename28/INCLUDE: symbol29/INCREMENTAL: {YES | NO} 30/LARGEADDRESSAWARE [: NO] 31/LIBPATH: dir32/LINK50COMPAT33/MACHINE: {ALPHA | ARM | IX86 | MIPS | MIPS16 | MIPSR41XX | PPC | SH3 | SH4} 34/MAP [: filename] 35/MAPINFO: {EXPORTS | FIXUPS | LINES} 36/MERGE: from = to37/NODEFAULTLIB [: library] 38/NOENTRY39/NOLOGO40/OPT: {ICF [, iterations] | NOICF | NOREF | NOWIN98 | REF | WIN98} 41/ORDER: @ filename42/OUT: filename43/PDB: {filename | NONE} 44/PDBTYPE: {CON [SOLIDATE] | SEPT [YPES]} 45/PROFILE46/RELEASE47/SECTION: name, [E] [R] [W] [S] [D] [K] [L] [P] [X] 48/STACK: reserve [, commit] 49/STUB: filename50/SUBSYSTEM: {NATIVE | WINDOWS | CONSOLE | WINDOWSCE | POSIX }[,#[. ##]] 51/SWAPRUN: {CD | NET} 52/VERBOSE [: LIB] 53/VERSION :#[. #] 54/VXD55/WARN [: warninglevel] 56/WINDOWSCE: {CONVERT | EMULATION} 57/WS: AGGRESSIVE here, our environment settings are half done, it is basically able to cope with situations where you do not need to use certain libraries and header files. As for the usage of libraries and header files, we can still remember the settings when we encounter them. Here we will make a small example to see if we have set them correctly, for example, hello world.

Enter a directory and create a hello. c
The content is very simple. printf is a string of characters.

Write the following code in your favorite Text Editor:

1 # include <stdio. h> 2 3 int main () 4 {5 printf ("abcdefg. "); 6 return 0; 7} Then go to the command line and enter the directory where the code is located in the command line. Here I am d: est
The execution process is as follows:

1 D:> cd test 2 3 D: est> cl hello. c 4 Microsoft (R) 32-bit C/C ++ Optimizing Compiler Version 12.00.8168 for 80x86 5 Copyright (C) Microsoft Corp 1984-1998. all rights reserved. 6 7 hello. c 8 Microsoft (R) Incremental Linker Version 6.00.8168 9 Copyright (C) Microsoft Corp 1992-1998. all rights reserved.10 11/out: hello.exe 12 hello. obj13 14 D: est> hello.exe 15 abcdefg. we can see that cl hello.chas compiled hello.exe and executed Lo.exe gets the output. So easy?
But here are a few questions to see if you can answer them.

1. Here is hello. c. If it is hello. cpp, does cl behave differently?

2. If there are two or more files, can cl be used to compile the exe file directly?

3. Can I change the entry to void main () or void start?

4. stdio. h everyone knows that it is C's standard library content. How does windows integrate it into the system?

5. Similarly, stdio. h is just a header file, and the specific function implementation is in the lib library. How does windows merge it into the exe file?

6. We just printed English characters. If we want to enter the Chinese character "Hello, world", what will happen? Why?

This is actually my doubt. It is also the content to be discussed in the next article, tentatively entitled "hello. c's question". I will try my best to answer it.

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.