From Windows to Linux - Programming - Cygwin, developing Linux program in Win, Linux program, Qiankun, smile [SmileOnce] smileonce@126.com 2004-7-23 All rights reprinted, please indicate http://blog.9cbs.net/ SmileOnce
Many friends with Windows are not accustomed to using Linux development environment. Although I am very happy to try it, it is often afraid that the Linux system disrupted her normal life: 1> The Linux system is broken, causing the Windows system to not live normally; 2> Linux development is too difficult, write the first A HelloWorld is not a difficulty of Java, and the environment is not impressed. For this, my opinion is: the road is still flat or steep, and it will be to go, if you are willing to invest in the community developed by Linux, you will not install the Linux system, you can't imagine the working environment. (In fact, it is really important to understand the principles of things, otherwise it is difficult to troubleshoot: such as the guiding principle, partition structure principle and Linux partition structure and file system, setting of environment variables, and a wide variety of compressed package installation packages The unzipped installation method, user management rights management, etc., so that the cultural and trivial cultural in the system is driven.
This article tries to skip this difficult step, enabling a Linux emulator in a Win environment (which is basically consistent with the command line development environment below Linux), teaches you to make a pure Linux with a short 20 minutes. GCC compiled HelloWorld. Just try to taste the taste before you buy a snack, isn't it a very pleasant thing? (Note: Cygwin In fact, not only this simulation, it is also a very effective tool for transplanting the Unix <-> WIN program, and some people use it to do embedded system development)
1. What is Cygwin? This question, you'd better google "Cygwin's history", perhaps you can get a more detailed answer. Briefly, Cygwin is a Linux simulation environment running on a Windows platform, which is the free software developed by Cygnus Solutions (the company has developed a lot of good things. The famous also has ECOS, but it has been acquired by Red Hat). Insert a nonsense, many friends do not understand the differences and links between Linux and UNIX, and briefly introduce it here. UNIX is a registered trademark, which is to meet a lot of conditions and pay the considerable fee to be authorized to use an operating system; Linux is UNIX's cloning version, which is a founder Linus and many world famous hackers. operating system. Why is there a lot of software between Linux and UNIX easy to transplant? Because Linux also meets the POSIX specification, it is similar to UNIX on the running mechanism. The following quotes online (source: http://blog.9cbs.net/glock18/archive/2004/07/10/38275.aspx), used to explain the working mechanism of Cygwin: Cygnus first put GCC, GDB, The GAS and other development tools have been improved to enable them to generate and explain the Win32 target file. Then they want to transplant these tools to the Windows platform. One solution is based on Win32 API's source code for these tools, which clearly requires a lot of work. Therefore, they have taken a different way - they wrote a shared library (that is, Cygwin DLL), encapsulated in the Win32 API (such as Fork, Spawn, Signals, SELECT, SOCKETS, etc.) That is, they wrote an analog layer of a UNIX system library based on Win32 API. This way, just connect these tools and this shared library together, you can use the cross-compiler on the UNIX host to generate a toolset that can run on the Windows platform. Based on these development tools on the Windows platform, Cygnus gradually puts other tools (almost no need to modify the source code, just modifying their configuration scripts) software transplanted to Windows. This way, running Bash and development tools on the Windows platform, user tools, feel like working on UNIX. For more detailed description of Cygwin implementation, please refer to Http://cygwin.com/cygwin-ug-net/highlights.html 2, Cygwin installation. Cygwin installation file is easy to find through Google. At present, there are two kinds of "network installations" and "local installation versions" on the domestic website. The standard release should be a network installation version. The two have no greatness, and the process of installing is described below.
After STEP1. After downloading, click the installation file (setup.exe) to install, the first screen is the GNU copyright description, click "Next (n) ->", enter the installation mode selection screen.
Step2. The installation mode has three kinds of "install from internet", "Download Form Internet", "Install from Local Directory". "Install form Internet" is directly from the Internet, which is suitable for the fast network speed. If you are not very fast like me, or if you have already installed the downloaded installation file, you will not download the direct installation next time, you should choose "Download Form Internet", download the installed file (about 40m about). In fact, the so-called "local installation version" is also a package after downloading all files from the Internet (for China National Affairs ^ _ ^) Step3. Next is the path to the installation destination path and the installation source file, then Just enter the path where you choose the installation package. Pay attention to Ah, here is a heavy action. I didn't see this step when I was first installed. As a result, I didn't put the GCC in, causing unable to compile the file. All Default Admin DEFAULT .... Devel Default Editors Default .... As shown above, you can change its status, such as default, install, uninstall on this TreeView, such as Default, Install, Uninstall, Reinstall four states. The default is the default state, and the default status of many tools is not installed. Here I chose the default on the default on the line, all installed, so as not to suffer. (Note: The tree controls here are different below. You try to point on all on all and the default behind the ALL, there will be different responses) STEP4. Point Next, the installation is successful. It automatically creates a shortcut on your desktop.
Ok, let's start my Linux journey below. Double click on the shortcut to enter the system. First introduce a few simple Linux commands. The PWD displays the current path CD to change the current path. When there is no parameters, enter the corresponding user's Home directory LS lists the files in the current directory. This command has N multi-parameters, such as ls -alps lists the current system process Kill kill a process MKDIR to create a directory RMDir Delete Directory RM Delete file MV file rename or directory to change the MAN online Help LESS display file's top line
Due to most of the commands under Linux, there are many parameters, which can be used in combination. So, whenever you don't know that the parameter is not clear, when the switch can be used, if you want to find how to use LS, you can type the $ man LS system echo information as follows: LS (1 ) FSF LS (1) NAME ls -. list directory contentsSYNOPSIS ls [OPTION] ... [FILE] ... DESCRIPTION List information about the FILEs (the current directory by default) Sort entries alphabetically if none of -cftuSUX nor - Sort. -a, --all do not hide entries starting with. -A, - almost-all do not list implied. and .. -b, --escape print octal escapes for nonchic characters - Block-size = size Use size-byte blocks: very all, hehe. Ok, more, say unintentional, let us write a Hello World program. # CD Enter the / home / administrator directory, my current login account is Administrator
# MKDIR SOURCE Create a subdirectory called SOURCE
# c c s 进 进 / Home / Administrator / Source
# vim hello.c
Start the VIM editor to write a program. Ok, now it is necessary to briefly introduce Vim. In the Linux, there are two major editors most historical. One is VI, and the second is Emacs. VI has now evolved into VIM, more powerful than current VI. Vim and Emacs are two distinct things, VIM emphasizes the completion of the function, whether it is looking, replace, regular expression match, compile, link, tired, function room jump, etc. Completed in the line, and it integrates the arrow keys above the four keys of HJKL, it can be said that VIM can basically do not have a mouse: P Emacs is in powerful articles, version control, simulate multiple The editing environment, performs various operations for text, which can be described as a powerful text processing system. Emacs is controlled by a combination of Ctrl Alt K; VIM is controlled by a simple command such as SE (quote from SET). Since only VIM is available in Cygwin (can I have an emacs I haven't tried it yourself), we will first experience the VIM: PVIM Load text files are divided into command mode and insert mode. Insert mode, as the name refers to enter editing text; command mode, the command mode is input to various VIM control commands, commonly used: i enters the editing mode h left shift J dropped K moving l right shift W storage Q to exit! Emphasis
Some commands can be used in combination. If you modify a file, you can use wq if you want to exit, if you want to give up the deposit, you can use Q! Hello everyone to experience it, remember: from editing The mode returned command mode Press "ESC", then press ":", in the input instruction, enter the editing mode from the command mode I, the first use of VIM is definitely very uncomfortable, 嘿嘿, but it is used to it, it is really labor-saving. We edit the hello.c file, type: #include
INT main (void) {Printf ("Hello World!");} then enter the WQ command to return to the command line. Enter the compile instruction: # GCC Hello.c -o Hello After successful compilation, you can look at # ls to see Hello.exe, hehe. Ok, let's run it. What is the effect of /HELLO? Not bad right? :)
Okey, now play a C Hello World, # vim world.cpp Enter: #include
Using namespace std;
Void main () {cout << "Hello World!";} Compiling C programs To run now with G # g world.cpp -o world, # ./world
What is the effect? All are masters, walking to this step should be compiled. It is not a problem. P.
Posted on July 23, 2004 3:48 PM href = "/ smileonce / services / pingback.aspx" Rel = "pingback">
Feedback # Reply: Developing Linux programs from Windows to Linux - Programming - Cygwin, developing Linux programs in Win 2004-07-23 3:58 PM Wenlong WU
Microsoft has also launched a simulated Unix running environment, Services for UNIX, similar Cygwin, product address is: http://www.microsoft.com/chn/windowsserver2003/sfu/default.mspx Even I have also intended to write an article Comparison of Cygwin and SFU :-)
# Don't know if there is downloaded there? : p 2004-07-23 4:25 PM smile
M $ Dongdong should not be free: P
# 回 回: From Windows to Linux - Programming - Cygwin, develop Linux programs in Win 2004-07-23 4:29 PM Wenlong WU
Download address: http://www.microsoft.com/windows/sfu/downloads/default.asp Just started to buy it, start free from version 3.5.
# 回: 到 程序 程序 程序 程序 程序 程序 程序 程序 程序 程序 程序 200 程序 200 程序 200 程序 200 程序 200 程序 200 程序 200 程序 程序 程序 200 程序 200 程序 200 程序 200 程序 200 程序 200 程序 200 程序 200 程序 200
Don't you use Java directly?
# 回 回: From Windows to Linux - Programming - Cygwin, develop Linux programs in WIN 2004-07-27 8:30 AM CCTV
Yes, tell how to use Java under Linux
# 回 回: From Windows to Linux - Programming - Cygwin, develop Linux programs in Win 2004-07-27 9:11 AM Java huh. The Java programming under Linux is numbered on Windows, and it will be done on Linux.
# 回 回: From Windows to Linux - Programming - Cygwin, develop Linux programs in Win 2004-07-27 12:44 PM Doodoofish
There are a lot of tools programmed on Linux, and individuals prefer Eclipse.
# 回 回: From Windows to Linux - Programming - Cygwin, develop Linux programs in Win 2004-07-28 12:25 AM Bobinet
Thanks to the author to provide such a master! I am making a GCC? Thank you!
# 回: 到 程序 从 从 程序 编 程序
How do you don't have VIM after installation?
# Xihonghong 2004-07-28 6:48 PM smile
It is estimated that it is not installed, see STEP3 is right?
# 回 回: From Windows to Linux - Programming - Cygwin, develop Linux programs in Win 2004-07-29 3:01 PM NOWCAN
All downloads seem to be 300m, absolutely not 40m.
# T nowcan 2004-07-29 4:25 PM smile
Online "Offline Installation Edition" is more than 40 megabits, less than 300m after all installation If online installation, you need to download 400M, 1.5g after all installation
# 回:: From Windows to Linux - Programming - Cygwin, develop Linux programs in Win 2004-07-29 4:54 PM Archer
Well, I am now in a question, at Cygwin Make My Program, Makefile's shell = / bin / sh, I can't find / bin / sh, but I can run directly in the Cygwin window / bin / sh, why what