Go language generates executable files through commands

Release: 2020-06-18 17:27:13
forward
3191 people have browsed it

Go language generates executable files through commands

After installing go, we usually set the GOROOT and GOPATH environment variables. However, sometimes due to the complex project structure in actual work, when the set GOPATH cannot meet the needs, it can be set in cmd Temporary GOPATH;

Many IDEs, such as IDEA, can also set global GOPATH and temporary GOPATH, but compiling executable files may be complicated or the app.conf configuration file cannot be loaded when compiled or run through the IDE. situation, I have encountered this pitfall.

So the go executable file is generated through commands.

  • For example, the project structure is like this:

Go language generates executable files through commands

Since it depends on beego in github.com, we need to add github.com Parent directory to GOPATH.

1. Open the cmd command window and use the command to set the environment variable for the path of the package to be compiled and the path of the dependent package, that is, GOPATH (this setting only takes effect for this window):

set GOPATH=E :ProgrammerRouteGoDevelopment\

2. Then set the operating system:

  • Generate the windows executable file:
set GOOS=windows
  • Generate linux executable file:
set GOOS=linux

3. Then execute go install

go install sayHello
Copy after login

in the src directory if no error is reported , the bin and pkg directories will be generated under GOPATH, and the executable file is in the bin directory, as shown in the figure:

Go language generates executable files through commands

Use versions after beego1.7.0 to run the go project with the IDE The configuration of app.conf cannot be loaded, nor can it be loaded using go install;

You can use go run main.go to load app.conf, and you can also use the bee tool to load it.

For more related knowledge, please pay attention to thego language tutorialcolumn

The above is the detailed content of Go language generates executable files through commands. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!