Build gccgo on ubuntu 12.04

283 views
Skip to first unread message

Robert Sandra

unread,
Sep 26, 2012, 11:26:38 AM9/26/12
to golan...@googlegroups.com
Hi all,

I am tring to install gccgo on ubuntu 12.04. I succeed to build gcc-4.7.1 with adding go to the --enable-languages like --enable-languages=c,c++,go. Then I get gccgo command in the bin folder of gcc4.7.1. I try to use gccgo -c test.go to build the following code:

// #include <stdio.h>
// #include <stdlib.h>
import "C"
import "unsafe"

func Print(s string) {
    cs := C.CString(s)
    C.fputs(cs, (*C.FILE)(C.stdout))
    C.free(unsafe.Pointer(cs))
}

func main(){
    Print("hello googc\n")
}

However, I got the following errors:
testc.go:5:9: error: import file ‘C’ not found
testc.go:9:11: error: reference to undefined name ‘C’
testc.go:10:5: error: reference to undefined name ‘C’
testc.go:10:19: error: reference to undefined name ‘C’
testc.go:10:27: error: reference to undefined name ‘C’
testc.go:11:5: error: reference to undefined name ‘C

I don't know where the problem is. Do I need to build the gccgo following the instructions shown on http://golang.org/doc/install/gccgo site? 
Since according to my understanding, after I build the gcc-4.7.1 with enabling go, I don't need to do the followings. Am I right? Thanks all.
svn checkout svn://gcc.gnu.org/svn/gcc/branches/gccgo gccgo
mkdir objdir
cd objdir
../gccgo/configure --prefix=/opt/gccgo --enable-languages=c,c++,go --with-ld=/opt/gold/bin/ld
make
make install

Robert Sandra

unread,
Sep 26, 2012, 11:27:54 AM9/26/12
to golan...@googlegroups.com
There is a package statement in the beginning of the test go file. I just forgot to copy that line.
package main

minux

unread,
Sep 26, 2012, 11:59:52 AM9/26/12
to Robert Sandra, golan...@googlegroups.com

On Wednesday, September 26, 2012, Robert Sandra wrote:
I am tring to install gccgo on ubuntu 12.04. I succeed to build gcc-4.7.1 with adding go to the --enable-languages like --enable-languages=c,c++,go. Then I get gccgo command in the bin folder of gcc4.7.1. I try to use gccgo -c test.go to build the following code:

// #include <stdio.h>
// #include <stdlib.h>
import "C"
import "unsafe"

func Print(s string) {
    cs := C.CString(s)
    C.fputs(cs, (*C.FILE)(C.stdout))
    C.free(unsafe.Pointer(cs))
}

func main(){
    Print("hello googc\n")
}

However, I got the following errors:
testc.go:5:9: error: import file ‘C’ not found
testc.go:9:11: error: reference to undefined name ‘C’
testc.go:10:5: error: reference to undefined name ‘C’
testc.go:10:19: error: reference to undefined name ‘C’
testc.go:10:27: error: reference to undefined name ‘C’
testc.go:11:5: error: reference to undefined name ‘C
You are using cgo, so you still have to install the Go command
from the go project.

After putting gccgo into your $PATH, I think this might work:
go build -compiler gccgo test.go

Reply all
Reply to author
Forward
0 new messages