我可以在 cgo 中使用 libtool 输出吗?

Can I use libtool output in cgo?

我调用的是从c++源代码编译的静态库。但是写依赖库很累,我发现 libtool 做得很好,例如,我的 libfoo.la 会有这样的东西:

dependency_libs=‘ /Users/roger/example/lib/bar/libbar.la -lm’

现在我在golang中调用libfoo.a,但是依赖关系会很复杂。 libfoo.a取决于libbar.alibbar.a取决于libhaha.a我可以在构建 golang 时使用 libfoo.la 吗?(或者以某种方式将 libfoo.a 及其所有依赖项放入一个 lib 文件中?)

can I make use of libfoo.la when I build golang?

没有。 Go 有自己的构建系统,它不知道 libtool 档案,只有系统上可用的标准 static/shared 库。

Now I am calling libfoo.a in golang, but the dependencies can be complicated.

静态库就是这样。这是改用共享库的原因之一。共享库在 Go 中也不是没有问题,但在某种程度上是易于管理的。

libfoo.a depends on libbar.a ,libbar.a depends on libhaha.a.

不是这样的:

package foo


// #cgo CFLAGS: -I...
// #cgo LDFLAGS: -L... -lfoo -lbar -lhaha -lm
// #include ...
import "C"
...

工作?

or some way make libfoo.a and all its dependencies into one lib file?

是的,这是可能的,但另一个问题。