Showing posts with label help. Show all posts
Showing posts with label help. Show all posts

Saturday, 21 January 2012

Build Google Go on Windows

** Important Note: The Go team now provides a Windows port of Go. This is the recommended way of installing Go on that platform but I will leave this here as an exercise to whomever would prefer to install Go this way. **

I've seen countless posts requesting a Windows port of Go. For quite some time there hasn't been one available but, thankfully, there is an experimental port available. However, as it turns out, you can also compile it yourself without waiting for someone else to do it for you. This gives you the advantage of always having an up-to-date version of Go by having immediate access to the latest release without having to wait for a build, or even using the weekly release. In order to do this, we'll need MinGW.

So, without further adieu, here is a step by step installation procedure to start using Go on Windows.

1) Install Msys and MinGW. You will need a POSIX compliant shell in order to build Go. I'm sure Cygwin would also be capable of building Go but I prefer Msys. For anyone new to Msys, or unfamiliar with using the CLI, I would recommend using the GUI installer. As per the golang documentation, you'll need to make sure you install the following tools: gcc,  glibc or some other C standard library, Bison, Make and Awk. All of these tools are available via the apt-like mingw-get tool. If you forget to download one of these tools during installation, don't worry. The mingw-get tool is accessible from within Msys.

2) Install Mercurial. Here you have two choices. One, you can try and build Mercurial from source on MinGW or you can do the sensible thing and download the Windows version. I highly recommend doing the latter. You can also get TortoiseHg if you require a GUI but if your only intention is to use it to download Go then I wouldn't bother. It's much simpler just using the CLI.

3) Open the Msys terminal. Assuming all is right with the world you will be in your home directory. You should now be able to use the following command, as taken from the Golang installation guide:

$ hg clone -u release https://go.googlecode.com/hg/ go

4) Change to the go/src directory and run all.bash.

$ cd go/src
$ ./all.bash

5) If all goes well, Go is now installed and ready to go! That's it! I recommend creating a .bashrc file and add the recommended environmental variables. Something simple like:

$ cat > ~/.bashrc << EOF
# .bashrc
export GOROOT="$HOME/go"
export PATH="$PATH:$GOROOT/bin"
EOF
$ . ~/.bashrc

Msys does not come with any kind of editor installed (not even ed). Vim is available through the repositories via mingw-get or you can just use your normal text editor for Windows to edit the file. There are plenty of other things you might wish put into your .bashrc, too, but that is beyond the scope of this article. If you installed Msys into the default installation directory, you would save it in "C:\MinGW\msys\1.0\<username>\.bashrc" where <username> is replaced with your name. Obviously.

I should mention that on my first attempt on building Go, the build script hung while trying to compile gprof. Sadly, I didn't have the presence of mind at the time to record on which file it got stuck on, so there's not much I can do to see if this is a Go or MinGW/Msys bug. Irregardless, I had to force-quit Msys by closing the window because no other method would unlock the process. Re-running the all.bash script a second time completed successfully and finally reported that, "ALL TESTS PASSED!" Now THAT is what I wanted to hear! Or, in this case, see.

You should now be able to use the Go tools from the 'cmd' shell but in order for the shell to find it you will need to manually adjust your %PATH% environmental variable in Windows, too. A simple way to do this on Windows 7 is to open the start menu, right-click on 'Computer' and select properties. Then, click the 'Advanced Settings' link on the left to open the advanced settings window. A button near the bottom of the window will allow you to alter your PATH variable. A simple search can show you how to do it on other versions of windows or via an alternate method.

And that, as they say is that. A native Windows build of Go. Provided you adjust some environmental variables, as noted in the 'Getting Started' documentation for Go, you are free to relocate the go tree to another location like "C:\Program Files (x86)". You may also want to build the 'hello world' application as an extra sanity test. You can install a Go IDE or add Go syntax highlighting to your favourite editor.

Tuesday, 9 August 2011

How to Get Help

Originally, this was going to be a part of another post but I've decided that this piece of information should really be on its own. The idea for this post comes mainly from my experiences and observations on the programming forums I frequent, namely the Ubuntu Programming Forums. Nothing is more frustrating than someone who won't help themselves.

So, my first piece of advice is: Try to figure it out for yourself, first. There is a lot of information on the Internet and in books. Asking for help should not be your go-to course of action. Indeed, consider it your last line of defense. Let's be honest, while it may be the easiest, it's certainly not the fastest and probably not the most exhaustive. Sometimes, you're lucky to get an answer all. So, search first and ask second.

If you want to get an answer quickly, learn how to use search engines properly. I can't stress this enough.  Think about what you're asking. Try to make your search terms very specific but not overly complicated. A good search will likely only contain a couple words. It should not be a full sentence or proper English (or whatever tongue you're searching in). "How do I compile a program," is less effective than, "compile c" isn't. After looking at the first couple results and you decide it's not helping (they're all on how to compile c on windows or in an IDE and you need to know how to compile it on the Linux command line) you need to grow your search criteria, "compile c linux command line." The order of terms isn't usually important. For more help on optimizing your search results try, "google search help," and blam, you get an answer.

My second piece of advice: When asking questions on a web forum make sure you ask something specific and give as much information as possible. Asking, "How do I compile a program," is so nebulous that if you get an answer at all, it likely won't be very friendly. You need to specify what language you need to compile, which operating system and/or distribution, and any prior experience you have. Saying something like, "I've done some searching and couldn't turn anything up..." or "After a couple searching, I'm still confused because..." will help but, let's face it, if you really haven't done that people are going to know. Assume they're a lot smarter than you are until they prove you wrong (and many will). Do your homework. Like I've said already, it becomes obvious quickly if you haven't. People become hostile if all you do is want them to do the work and not do any yourself. Try and be as self-sufficient as possible. Take the initiative. Only ask questions when you just can't figure it out yourself and searches aren't getting you anywhere.

My third piece of advice: Make sure your question is relevant to the forum you're in. If you're on a Linux forum don't ask a Windows-only question. It's not that people can't answer or will be offended by it (though they might) but do you really think that is going to be the best source of answers? Doesn't it make sense to go where a lot of other Windows developers are? Asking why a program won't install or how to create a web page on a programming forum (happens all the time) make sense to you? What relevance does it have? Why kind of help are you really expecting? Would you ask a doctor how to build a house, ask a police officer how to tend your lawn or a cab driver how to fly an airplane? Basically, don't ask off-topic questions! If you have an honest question, no matter how basic or silly, and you've clearly tried to help yourself, then most people will be happy to help.

My last piece of advice: Think for yourself. Think about what you've been told and see if it makes sense. Does it agree with what you already know? Always check more than once source to make sure they agree (in computing, they often don't). There's a lot of bad advice (hopefully, this isn't) out there so it's always a good idea to not accept the first thing you read and keep looking at at least two or three alternative sources. Make sure the sources are credible too. Why would you trust the authority of someone if they've done nothing to back it up. There's a huge difference between theoretical knowledge and practical knowledge.

Good hunting.