FAQ
Hi,

I want to use a c++-Library from go.
Google told me about SWIG.
First off i tried to replicate this example:
http://golang.worleyspace.com/2010/10/swig-go.html

It is a simple .c and .i File.
I sucessfully ran
% swig -go example.i
% gcc -c -fpic example.c
% gcc -c -fpic example_wrap.c
% gcc -shared example.o example_wrap.o -o example.so
% usr/lib/go/pkg/tool/linux_amd64/6g example.go
% usr/lib/go/pkg/tool/linux_amd64/6c example_gc.c

% pack grc example.a example.6 example_gc.6


Now i wrote a main.go which looks like the following:
[code]
package main
import (
"example"
)
func main() {
example.Fact(4)
}[/code]

Running % usr/lib/go/pkg/tool/linux_amd64/6g main.go results in
main.go: Can't find import "example".

The file structure is the following:
main.go is in $HOME/temp/
All the example files are in
$HOME/temp/src/example/

What am i doing wrong here?

--

Search Discussions

  • Minux at Sep 19, 2012 at 8:02 am

    On Wed, Sep 19, 2012 at 7:03 AM, Mathews wrote:

    I want to use a c++-Library from go.
    Google told me about SWIG.
    First off i tried to replicate this example:
    http://golang.worleyspace.com/2010/10/swig-go.html

    It is a simple .c and .i File.
    I sucessfully ran
    % swig -go example.i
    % gcc -c -fpic example.c
    % gcc -c -fpic example_wrap.c
    % gcc -shared example.o example_wrap.o -o example.so
    % usr/lib/go/pkg/tool/linux_amd64/6g example.go
    % usr/lib/go/pkg/tool/linux_amd64/6c example_gc.c

    % pack grc example.a example.6 example_gc.6


    Now i wrote a main.go which looks like the following:
    [code]
    package main
    import (
    "example"
    )
    func main() {
    example.Fact(4)
    }[/code]

    Running % usr/lib/go/pkg/tool/linux_amd64/6g main.go results in
    main.go: Can't find import "example".

    The file structure is the following:
    main.go is in $HOME/temp/
    All the example files are in
    $HOME/temp/src/example/
    6g -I example main.go
    6l -L example main.6

    or you can set GOPATH=$HOME/temp
    and do 'go build main.go', it will recompile the example package, but it
    should be fully
    transparent.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 18, '12 at 11:28p
activeSep 19, '12 at 8:02a
posts2
users2
websitegolang.org

2 users in discussion

Mathews: 1 post Minux: 1 post

People

Translate

site design / logo © 2022 Grokbase