最新消息:

win7下安装MinGW和MSYS并设置环境变量(二)

软件开发 王杭州 4857浏览 0评论 [编辑]

安装好MinGW和MSYS后,需要设置环境变量,然后更好的使用其中提供的小工具。

如果我们使用ls命令查看当前目录下的文件列表,但是得到如下图所示的结果。

ls命令不起作用,这是因为无法找到ls命令。为了解决这一问题,需要修改环境变量。

在命令提示行里输入path,查看当前的环境变量path的值。

环境变量是一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息。例如path,当要求系统运行一个程序而没有告诉它程序所在的完整路径时,系统除了在当前目录下面寻找此程序外,还应到path中指定的路径去找。用户通过设置环境变量,来更好的运行进程。

可以通过在命令提示符中使用set命令设置路径,这种方式只对当前窗口有效,当窗口关闭后,设置的环境变量失效。

为了永久保留环境变量的修改效果,本文详细介绍具体的操作步骤。

打开“控制面板”。

选择“系统和安全”。

选择“系统”。

选择”系统属性”。

点击“环境变量”。

选取“Path”,进行编辑。

在变量值的编辑框内添加mingw和msys的路径,中间用分号隔开,注意使用半角的分号,也就是英文输入法下的“;”

C:\MinGW\bin;C:\MinGW\msys\1.0\bin

点击“确定”,退出当前操作。再次打开命令提示符,输入path

可以看到新添加的路径,表明修改路径成功。输入输入uname –help查看。

C:\Users\Administrator>uname –help

Usage: uname [OPTION]…

Print certain system information.  With no OPTION, same as -s.

-a, –all                print all information, in the following order,

except omit -p and -i if unknown:

-s, –kernel-name        print the kernel name

-n, –nodename           print the network node hostname

-r, –kernel-release     print the kernel release

-v, –kernel-version     print the kernel version

-m, –machine            print the machine hardware name

-p, –processor          print the processor type or “unknown”

-i, –hardware-platform  print the hardware platform or “unknown”

-o, –operating-system   print the operating system

–help     display this help and exit

–version  output version information and exit

Report bugs to <bug-coreutils@gnu.org>.

C:\Users\Administrator>

表明路径设置成功。

在GNU工具中,自动化项目管理的make命令功能强大,在设置好环境变量的路径后可以通过输入make –help来随时查看make命令的选项帮助。

C:\Users\Administrator>make –help

Usage: make [options] [target] …

Options:

-b, -m                      Ignored for compatibility.

-B, –always-make           Unconditionally make all targets.

-C DIRECTORY, –directory=DIRECTORY

Change to DIRECTORY before doing anything.

-d                          Print lots of debugging information.

–debug[=FLAGS]             Print various types of debugging information.

-e, –environment-overrides

Environment variables override makefiles.

-f FILE, –file=FILE, –makefile=FILE

Read FILE as a makefile.

-h, –help                  Print this message and exit.

-i, –ignore-errors         Ignore errors from commands.

-I DIRECTORY, –include-dir=DIRECTORY

Search DIRECTORY for included makefiles.

-j [N], –jobs[=N]          Allow N jobs at once; infinite jobs with no arg.

-k, –keep-going            Keep going when some targets can’t be made.

-l [N], –load-average[=N], –max-load[=N]

Don’t start multiple jobs unless load is below N.

-L, –check-symlink-times   Use the latest mtime between symlinks and target.

-n, –just-print, –dry-run, –recon

Don’t actually run any commands; just print them.

-o FILE, –old-file=FILE, –assume-old=FILE

Consider FILE to be very old and don’t remake it.

-p, –print-data-base       Print make’s internal database.

-q, –question              Run no commands; exit status says if up to date.

-r, –no-builtin-rules      Disable the built-in implicit rules.

-R, –no-builtin-variables  Disable the built-in variable settings.

-s, –silent, –quiet       Don’t echo commands.

-S, –no-keep-going, –stop

Turns off -k.

-t, –touch                 Touch targets instead of remaking them.

-v, –version               Print the version number of make and exit.

-w, –print-directory       Print the current directory.

–no-print-directory        Turn off -w, even if it was turned on implicitly.

-W FILE, –what-if=FILE, –new-file=FILE, –assume-new=FILE

Consider FILE to be infinitely new.

–warn-undefined-variables  Warn when an undefined variable is referenced.

This program built for i686-pc-msys

Report bugs to <bug-make@gnu.org>

C:\Users\Administrator>

GNU工具中的编译器是gcc,可以通过输入gcc –help 查看gcc命令的选择。

C:\Users\Administrator>gcc –help
Usage: gcc [options] file…
Options:
  -pass-exit-codes         Exit with highest error code from a phase
  –help                   Display this information
  –target-help            Display target specific command line options
  –help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumen
ted}}[,...]
                           Display specific types of command line options
  (Use ‘-v –help’ to display command line options of sub-processes)
  –version                Display compiler version information
  -dumpspecs               Display all of the built in spec strings
  -dumpversion             Display the version of the compiler
  -dumpmachine             Display the compiler’s target processor
  -print-search-dirs       Display the directories in the compiler’s search path
  -print-libgcc-file-name  Display the name of the compiler’s companion library
  -print-file-name=<lib>   Display the full path to library <lib>
  -print-prog-name=<prog>  Display the full path to compiler component <prog>
  -print-multiarch         Display the target’s normalized GNU triplet, used as
                           a component in the library path
  -print-multi-directory   Display the root directory for versions of libgcc
  -print-multi-lib         Display the mapping between command line options and
                           multiple library search directories
  -print-multi-os-directory Display the relative path to OS libraries
  -print-sysroot           Display the target libraries directory
  -print-sysroot-headers-suffix Display the sysroot suffix used to find headers
  -Wa,<options>            Pass comma-separated <options> on to the assembler
  -Wp,<options>            Pass comma-separated <options> on to the preprocessor
  -Wl,<options>            Pass comma-separated <options> on to the linker
  -Xassembler <arg>        Pass <arg> on to the assembler
  -Xpreprocessor <arg>     Pass <arg> on to the preprocessor
  -Xlinker <arg>           Pass <arg> on to the linker
  -save-temps              Do not delete intermediate files
  -save-temps=<arg>        Do not delete intermediate files
  -no-canonical-prefixes   Do not canonicalize paths when building relative
                           prefixes to other gcc components
  -pipe                    Use pipes rather than intermediate files
  -time                    Time the execution of each subprocess
  -specs=<file>            Override built-in specs with the contents of <file>
  -std=<standard>          Assume that the input sources are for <standard>
  –sysroot=<directory>    Use <directory> as the root directory for headers
                           and libraries
  -B <directory>           Add <directory> to the compiler’s search paths
  -v                       Display the programs invoked by the compiler
  -###                     Like -v but options quoted and commands not executed
  -E                       Preprocess only; do not compile, assemble or link
  -S                       Compile only; do not assemble or link
  -c                       Compile and assemble, but do not link
  -o <file>                Place the output into <file>
  -pie                     Create a position independent executable
  -shared                  Create a shared library
  -x <language>            Specify the language of the following input files
                           Permissible languages include: c c++ assembler none
                           ‘none’ means revert to the default behavior of
                           guessing the language based on the file’s extension
Options starting with -g, -f, -m, -O, -W, or –param are automatically
 passed on to the various sub-processes invoked by gcc.  In order to pass
 other options on to these processes the -W<letter> options must be used.
For bug reporting instructions, please see:
<http://gcc.gnu.org/bugs.html>.
C:\Users\Administrator>
同样的方法,我们可以安装gvim程序,这是一款功能强大的编辑器程序,并将其所在目录设置在环境变量中。
编写helloworld程序。
输入:wq,或者ZZ,保存并且退出。输入gcc helloworld.c -o helloworld命令,编译helloworld.c文件。
运行编译出的可执行程序helloworld,在命令行中输入helloworld,回车。
至此,我们已经在windows 7上成功安装了GNU环境,并且设置了好了环境变量,之后,就可以在这个环境下进行相应的开发工作。

转载请注明:王杭州的个人网页 » win7下安装MinGW和MSYS并设置环境变量(二)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址