Learning Go: Go for iPhone/iPad

January 28, 2012

Strictly speaking, it is hard to say that this post is about “learning” the Go language. I just want to tell a story: after I successfully (but might illegally) installed GCC 4.2 on my iPhone 4, I went on to build Go. However, I got the following error messages:

Make.inc:79: *** Invalid $GOOS ‘darwin’ for GOARCH=arm; must be linux. Stop.
Did not find Go environment variables.

Then I searched “go darwin arm” in go-nuts group, the result leads me to a very new (Jan 7, 2012) and exciting work — a darwin/arm port of Go.

However, I also noticed a claim by the Go authors at the bottom of the discussion thread:

Date: Sat, 21 Jan 2012 15:48:18 -0500
Subject: Re: [golang-dev] Re: Darwin/ARM (aka. iOS) port of Go is READY
From: Russ Cox
To: minux
Cc: golang-dev@googlegroups.com

Sorry, I meant to reply about this before. We have decided
not to include the darwin/arm code in the main tree until there
is a way to run it on an ordinary iDevice without any kind of
“jailbreaking”. If the port advances to that point, please let
us know, but until then I’m afraid you’ll need to maintain your
own copy.

What a pitty for the official Go community~~ But so what! My best appreciation to minux, the author of the Darwin/ARM port of Go.


How to Install GCC 4.2 on iPhone

January 28, 2012

I have an iPhone 4 (16GB) running iOS 5.1. After jailbreak it using redsn0w and installing Cydia, I am able to ssh from my computer to the iPhone. Then, following this great blog post: http://blog.syshalt.net/index.php/2010/09/12/compile-c-applications-with-gcc-on-ios-4-iphone/, I installed GCC 4.2.1 on my iPhone. I also installed vim, nano and ping using apt-get install. Jailbreaking is great!

Here copy-and-pastes the content of the post mentioned above:

———————————————-

Here is what you need to do in order to be able to compile and run a C application on iphone:

1. You will need to Jailbreak the iPhone first, search on google for more info.
2. Install OpenSSH from Cydia.
3. Connect iPhone to your wireless network and SSH to it.
4. Download this application using: wget http://www.syshalt.net/pub/iphone/gcc-iphone/fake-libgcc_1.0_iphoneos-arm.deb
5. Install libcc using: dpkg –i fake-libgcc_1.0_iphoneos-arm.deb
6. Install iphone-gcc using this command: apt-get install iphone-gcc
(you can download this version from my website: iphone-gcc if does not work on your device the one that is installed by default)
7. Download using: wget http://www.syshalt.net/iphone/gcc-iphone/sdk-2.0-headers.tar.gz
8. Untar with command: tar -xvzf sdk-2.0-headers.tar.gz
9. Enter in the new created folder with: cd include-2.0-sdk-ready-for-iphone
10. Copy all files to include folder with command: cp –r * /usr/include
11. Now type: cd .. in order to return to the previous folder
12. Download using: wget http://www.syshalt.net/iphone/gcc-iphone/gcc_files.tar.gz
13. Untar with command: tar -xvzf gcc_files.tar.gz
14. Enter in the new created folder with command: cd gcc_files
15. Copy all files to /usr/lib using command: cp –r * /usr/lib
16. Install ldid to sign the application (this will prevent iOS to kill the application at startup) using: apt-get install ldid
17. Sign your compilet aplication using: ldid –S <application>
18. Run the application using: ./<application>

Suggestion: Install using: apt-get install nano
This will help you code easy directly from terminal.

Here is an example of hello world using C and gcc to compile on iPhone iOS 4:

I used nano hello.c in terminal to open a new files and writed this simple application:

#include <stdio.h>
int main() {
printf(“hello, world\n”);
return 0;
}

and then CTRL+X to save it, then I typed: gcc –o hello hello.c and after that ldid –S hello
Now you can run your application using ./hello


Using Clang: C++0x Features

January 23, 2012

I am using Ubuntu Linux 10.10, with which, comes Clang based on LLVM 2.8. When I use Clang to build google-test, it complains that “variadic template” is a C++0x feature and is not yet supported.

However, the Clang installed by Homebrew on my Mac OS X 10.7 (Lion) is based on LLVM 3.0 and works well with google-test.

The homepage of LLVM listed pre-built Clang and LLVM 3.0 for Ubuntu 11.04 and 11.10. So I guess I would have to upgrade to at least Ubuntu 11.04.

FreeBSD 9.0 comes with Clang based on LLVM 3.0.


Python under Linux, Mac OS X and FreeBSD Tells Differently

January 21, 2012

It is interesting: under Linux and Mac OS X running on x64 computers, Python 2.7 tells the machine is ‘x64_64′; whereas under FreeBSD, Python 2.7 tells ‘amd64′. You can try:
import platform
platform.machine()


Using Clang: Linkers with Different Platforms

January 20, 2012

I am using clang++ as the linker with both Ubuntu Linux and Mac OS X. The Ubuntu version invokes collect2, which has parameters –whole-archive and –no-whole-archive to force linking libraries, whereas the Mac OS X version invokes ld (llvm based), which has -force_load for the same purpose.


Using Clang: Cannot Find Standard C++ Library

January 20, 2012

When I use clang as the linker to link a C++ program, it complains cannot find standard symbols like std::cout. But if I use clang++ as the linker, it works. However, on both Ubuntu and Mac OS X, clang++ is just a symbolic link to clang! I guess when clang runs, it checks the name in which it was started and work accordingly.


Using Clang: Cannot Find Standard C++ Header Files

January 20, 2012

I got a problem with clang today: it complains cannot find standard C++ header files.

So I used two magic options: clang -v -E, which outputs details about how it tries to find the header files. This reveals that clang finds in /usr/local/c++/4.4.x, but not including /usr/local/c++/4.5.1, which is my only version installed together with GCC 4.5.1.

So, my solution is simply sudo apt-get install g++-4.4. (Note that is not enough to install gcc-4.4, because that does not bring you C++ header files and libraries.)


用Go语言实现Design Patterns

January 1, 2012

王海磊提醒我注意一篇论文:GoHotDraw: Evaluating the Go Programming Language with Design Patterns。这篇论文里介绍了作者用 Go 语言实现了三种常见的 design patterns:singleton、adaptor 和 template method。作者说,其实他实现了所有的 23 种 GoF design patterns,文中只说了上述三种。

除了这篇论文,我注意到这篇blog:Design patterns in Go programming language 里,作者介绍了如何用 Go 实现另外三种 design patterns:command, strategy 和 factory。

在我的这篇幻灯片里,我本来试图从 design patterns 如何用 Go 实现的角度来介绍 Go 语言。但是因为总结的不够,所以没有这么写。希望接下来能总结一下如何使用 Go 语言。

当然,纯粹的考虑一种语言如何实现一种 pattern 是机械的。一种观点是:如果需要一种 pattern,则说明使用的语言缺乏对应的语法。比如,这篇题为 The (lack of) design patterns in Python 幻灯片里,作者 Joe Gregorio 展示了一些用 Java 和 C++ 需要专门描述的 designs,如果用 Python,则只需少数几行,以至于没必要总结成一种 pattern。

在我的这篇博文里,列了 Peter Novig 的一个幻灯片,其中说 23 种常见 design patterns 中的 16 种,在 Lisp 语言种都有语法可以支持。


Latent Dirichlet Allocation: The Gritty Details

January 1, 2012

This is my learning note on the LDA model: Latent Dirichlet Allocation: The Gritty Details


A Learning Note on Go

December 13, 2011

This deck is my learning note about the Go programming language: Ready To Go? .


Follow

Get every new post delivered to your Inbox.