A little problem with the Go language compilation run

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Reprint: http://c2pblog.sinaapp.com/archives/355


Simply talk about the compilation run of the Go language.

Golang and C + + are compiled languages, first of all to write the source file, then compile, and finally run. These days in the use of the IDE has always been a key to run, there is no good understanding of the differences between compilation and running. And there are a few small problems in Linux that have to rethink the difference. Although the Golang compile speed, but we actually use the time must be to use the executable file, you give me a source code is meaningless, and in the actual project, your code will run on many machines, every minute will run many times, And then if you're wasting time at compile time, it's going to cost a lot. So we have to do some of the corresponding processing, the Golang source files are compiled into an executable file, and then directly in use when the implementation of the good.

There are two commands: Go build xxx.go and go run xxx.go

go build compiles the source code into an executable file, with the source file stripped of the  .go suffix, and the go run one step and compiles directly. When using go build, if this file requires external parameters, we do not need to take the parameters to compile, as long as the source file itself is good, but use go run to pay attention to have no parameters, and in conjunction with the previous blog discussed the method to do the corresponding processing. When using go run, if there are errors will be error, no error will generally run directly out of the results, using go build error will be errors, but the successful compilation will not be prompted. Run compiled files need to use  ./XXX   Such format, that is, dot + slash + filename + parameters [if any], this time to note that the runtime is not to add a suffix. Go. Generally running compiled files can be very fast.

Simply put, if you do not want your source code to be seen by others, you can only provide executable files, as well as related usage methods, no need to provide source files. It's just that you have to do all the testing on your own before you commit the code, and there's an unnecessary hassle.


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.