SWIG and go. Problem to create executables

Hello,

I´m trying to wrap c++ code in Go code, but I have some problems. I´m using Go for linux, the version of Go is 1.6.2, and to wrap the code I´m using SWIG, and the version of SWIG is 3.0.8. I´m following the SWIG manual and I put a file called example.i in GOPATH/src, and then SWIG manual says that I have to execute:

                         “swig -go -cgo -intgosize 64 example.i”

The code of example.i is:

        %module example
        %{
        extern int test(int n);
        %}

         extern int test(int n);

This generate two files, example.go and example_wrap.c (I don´t know if it should
generate a file .cpp o .cxx).

When I do “go build” (as SWIG manual says), I get an error because the function test is not implemeted in example_wrap.c. I solve this, adding this code at the end of test_wrap.c:

     int test(int a){
       return a+1;
     }

Now, when I do “go build”, I don´t have any error. So, now, I want to execute the go program, so I execute “go run example.go”, but I get this error, that I don´t know how to solve:

  go run: cannot run non-main package

I would like to know if I´m doing something wrong and how is the process to generate the files to execute Go code with c++ wrapped.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.