SWIG + Go:动态符号

时间:2015-05-20 17:37:07

标签: go swig

我正在尝试使用SWIG在Go中包装一个C ++库,但是当我尝试使用该包时,我遇到了构建错误,因为我升级到了Go 1.4.2。

这个包可以在这里找到: https://bitbucket.org/evanh/goewah

它包含.swigcxx文件以及C ++标头。作为参考,我正在尝试与此库进行交互:https://github.com/lemire/EWAHBoolArray

按照SWIG网站上的说明,我可以构建我的软件包并将其安装在我的机器上。我无法弄清楚如何让Go自动读取我的.swigcxx文件并构建软件包,因此我必须添加一个手动调用所有命令的Makefile。

但是,库的构建和安装没有错误。在Go 1.3.3上,我也可以使用包没有问题。但是,在Go 1.4.2中运行相同的程序会导致许多构建错误。

我的测试程序:

package main

import (
    "fmt"
    "bitbucket.org/evanh/goewah"
)

func main() {
    x := goewah.NewEWAHBoolArray()
    x.Set(1)
    x.Set(2)
    fmt.Println(x.Get(1))
}

我在尝试构建它时看到的错误:

# command-line-arguments
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_sizeInBits: unsupported  relocation for dynamic symbol _wrap_EWAHBoolArray_sizeInBits (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_isEmpty: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_isEmpty (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_toIntArray: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_toIntArray (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_numberOfOnes: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_numberOfOnes (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_readStr: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_readStr (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_writeStr: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_writeStr (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_read__SWIG_1: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_read__SWIG_1 (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_read__SWIG_0: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_read__SWIG_0 (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_write__SWIG_1: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_write__SWIG_1 (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_write__SWIG_0: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_write__SWIG_0 (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_reset: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_reset (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_logicalandnot: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_logicalandnot (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_logicalxor: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_logicalxor (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_logicalor: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_logicalor (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_logicaland: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_logicaland (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_inplace_logicalnot: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_inplace_logicalnot (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_logicalnot: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_logicalnot (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_set: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_set (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_get: unsupported relocation for dynamic symbol _wrap_EWAHBoolArray_get (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_new_EWAHBoolArray: unsupported relocation for dynamic symbol _wrap_new_EWAHBoolArray (type=1 stype=32)
bitbucket.org/evanh/goewah._wrap_EWAHBoolArray_get: unhandled relocation for _wrap_EWAHBoolArray_get (type 32 rtype 1)
too many errors

1 个答案:

答案 0 :(得分:0)

想出来。我也必须链接到C库。修正了以下代码。

package main

//#cgo LDFLAGS: -L/usr/local/lib -lewah
import "C"

import (
    "fmt"
    "bitbucket.org/evanh/goewah"
)

func main() {
    x := goewah.NewEWAHBoolArray()
    x.Set(1)
    x.Set(2)
    fmt.Println(x.Get(1))
}