Run the first go program with Eclipse

Source: Internet
Author: User

Windows 10 Home Chinese version, go version go1.11 windows/amd64,

Eclipse IDE for C + + developers Photon Release (4.8.0),

Goclipse 0.16.1 (v201607061938),

Immediately after the previous blog post, it is now possible to use Eclipse to develop GO programs: Build projects, build source files, compile, run, test, debug ...

This article describes the process of using eclipse to run the first go project and the pits in which it is trampled.

Build a project

The following D:\eclipse-cdt\ws is the Eclipse workspace-later changed, and after the change, you need to configure the Window->preferences->go again:

Successful Project Establishment:

Project tree structure, SRC Preliminary understanding for the release source, bin Storage compile, run, debug and other resulting executable files (details need to dig), Build targets is very important, involving the back of a pit debugging.

Building the source program

This is a mistake.--go language to the project directory structure is some provisions (see some of the web blog also mentioned, but also need to dig), and put the program directly in the SRC directory:

The source file New_file.go is generated under the project SRC:

Modify the test program for your needs:

Package main import ("FMT") func main () {FMT. Println ("Here I come!")}

Execute the program--encountered a problem (first) , do not:

Resource doesn ' t has a corresponding GO package.

After selecting Go application Runtime in run configurations, the following prompt appears:

After reviewing some articles, create a new pkg1 under SRC and put the above source files in it:

Executing the program again, the second problem arises-the executable file is not found in the bin directory where the project is located:

After searching, the executable program was found under the bin of the Go installation directory--pkg1.exe--but, why? :

" stumbled " opens the build Targets under the project, showing the project's Properties dialog box (property for go961):

found that the (Optional) Path of generated executable is shown to use the default, but what is the default?

After reading the above content, I do not know how to solve the problem! So, experiment!

Open run configurations, "randomly" modify the configuration, and run the program (the reader can skip this part because some of the configuration is wrong):

Because the executable file that was generated after the project compilation run ran to the Bin folder in the Go installation directory, the path of launch executable inside the run configurations is canceled with the use default, and configure the executable program's path to the Go installation directory under the project executables:

Execute again, run the program successfully in Eclipse, and get the expected results!

However, I still like the executable program appears in the Project Bin directory Ah! Why is that? Take a look at some of the network data (time-consuming and laborious) ,"A flash of inspiration"! As if I had installed go 1 weeks ago, as if I had configured an environment variable Gobin, was it caused by it?

Delete this environment variable!!!

Reconfigure run configurations--to check Use default:

Run the project again--Success! The executable program Pkg1.exe appears under the Bin directory of the project!

Well, the first go program just runs!

180906 1806 Additional Notes:

1. Replace Eclipse's workspace

During the testing process, I replaced the working directory of Eclipse--window->preferences->startup and shutdown->workspaces:

Select the prompt for workspace on startup and restart Eclipse to change the working directory.

shows that after changing the working directory, Eclipse has two working directories, the most recent being at the top, and the default working directory at the next startup.

2.Go Project Import

After changing the working directory, open Eclipse again and discover that the previous project go961 does not exist-because the project is not available in the new working directory.

You know that Eclipse has a project import function, so do project import ( Note that the pre-import project has been copied to the new working Directory yourself ):

An error occurred importing the project:

The import project has no goroot, Gopath:

Each tool in the Window->preferences->go is empty:

Workaround: Deselect the user default location under GOFMT, and configure it manually in one.

Then open run configurations to view the run configuration, then execute: The go package to build of the import project is empty, execution fails!

Modify run configurations configuration, re-execute: Success!

3. Set the project default encoding to UTF-8

The default is System GBK, modified to UTF-8:

Since all subsequent projects are likely to be UTF-8 encoded, modify the working directory encoding for UTF-8 for the entire eclipse:

Window->preferences->general->workspace

Although the global configuration, but the lone thought, or should be in the new project when the individual configuration of its code for the utf-8--porting project will not because of the eclipse default encoding different and error (guess)!

4. Build a second project: Success!

--------Split Line--------

However, there are still many questions:

1. What are the meanings of the environment variables for each go language?

2.GOBIN will affect the use of the Go command to install software, such as Gocode, Guru, and so on, the lone discovery before the installation of Guru, not only C:\Go\bin below Guru.exe, there is a gopath under Guru.exe.

3. When you create a new go source file, there are three options, which are the source files?

When you select a source file type of command, there are three options under it, and what do they mean? In which applications can I use them?

5.Build targets how to configure? How do I configure the properties of the Go project?

How does the build command in 6.Run configurations be configured?

7. What software can I install with go.exe, in addition to the previous development environment?

8.GoClipse is 2016, is it too old? What IDE does Google use for Go development?

What are the common application areas for 9.Go languages? How to make it more effective?

How can 10.Go language be used in conjunction with GitHub? Previously found that you can download and install the program on GitHub, then upload to your own library?

What are the standard libraries for 11.Go languages? Third-party libraries?

......

A lot of problems, but also need more depth to do! Before I saw someone using go language to write Web server, feel very cow Ah! Other web development is a thread-based Web server!

And what are the strengths of the go language? Take advantage of their strengths to learn! Prior to learning Python, this strategy was not adopted, resulting in a lot of time (a few months) on crawlers and web development, which is now a blank for Big data processing analysis, artificial intelligence, etc. using Python! So, learn the go language to change strategy!

I have seen the beginner's Go language tutorial before, so I don't remember anything particularly difficult at the moment.

So, next, understand the application of the go language, the lack of basic knowledge!

Fortunately you can visit it in the wall of the official website! Otherwise you will be the same as Android development to give up!

Run the first go program with Eclipse

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.