是否有一个示例如何使用SWIG生成GO Build的C Buidings
Is there an example how to use SWIG to generate C++ buidings with go build?
我想用" go Build"构建我的项目。我没有找到任何文档如何将SWIG与GO构建过程集成在一起。而且非常重要的是,它应该是C 示例C很容易。
foo.swig
/* foo.i */
%module foo
%{
#include "foo.h"
%}
%include "foo.h"
foo.h
#pragma once
int foo(int a, int b);
class MyClass {
int a,b,c;
public:
MyClass(int a, int b, int c): a(a),b(b),c(c) {}
int foo() {
return (a+b)*c;
}
int bar() {
return a*(b+c);
}
};
foo.cpp
#include "foo.h"
int foo(int a, int b){
return a*b;
}
main.go
package foo
import "fmt"
func main(args []string) {
fmt.Println("Hello World!")
fmt.Println(foo.foo(12, 17))
}
输出
arne@ad-X201t ~/g/s/g/k/swig-test> go build
# github.com/krux02/swig-test
In file included from $WORK/github.com/krux02/swig-test/_obj/foo_wrap.c:194:0:
./foo.h:5:1: Fehler: unbekannter Typname: »class«
./foo.h:5:15: Fehler: expected »=«, »,«, »;«, »asm« or »__attribute__« before »{« token
/tmp/go-build724218913/github.com/krux02/swig-test/_obj/foo_wrap.c: In Funktion »_wrap_MyClass_set«:
/tmp/go-build724218913/github.com/krux02/swig-test/_obj/foo_wrap.c:225:3: Fehler: unbekannter Typname: »class«
/tmp/go-build724218913/github.com/krux02/swig-test/_obj/foo_wrap.c:226:3: Fehler: unbekannter Typname: »class«
/tmp/go-build724218913/github.com/krux02/swig-test/_obj/foo_wrap.c:229:5: Fehler: unbekannter Typname: »class«
[...]
错误很明显,Swig试图将所有内容构建为C库。
要测试它,只需复制:
go get github.com/krux02/swig-test
查看在go build
中添加了SWIG支持的错误报告,看起来它决定如何根据文件扩展名来编译SWIG包装器:
-
.swig
文件被视为c -
.swigcxx
文件被视为C
如果将foo.swig
重命名为foo.swigcxx
,则应使用正确的SWIG标志和编译器。
,如http://golang.org/cmd/go/,仅当您的构建文件以.swigcxx结束时,-c 选项才会传递给swig。
有关使用C 的示例,请参见GO源中的MISC/SWIG/回调。
相关文章:
- 如何使用ndk-build.cmd构建Android.so文件
- CMake "--target install"无需"--build"命令行
- 库标题在标题中不可见,但在 cmake build 下.cpp文件中完全可见.为什么?
- Android Studio:如何在build.gradle中定义自定义宏(针对不同的构建变体),并让原生C / C++
- 加载"D:UsersPublicDocumentsopencvbuildx64vc14binopencv_world340d.dll",找不到或打开PDB文件
- 为什么'Go To Definition'给我多种选择?
- meson-build:wxWidgets 资源文件,用于 Windows 未构建
- 为什么在 Go 中将 float64 转换为 int32 会给出负数?
- 为 g++ build 设置超时,为 Sublime Text 运行?
- build error : undefined reference to `yyFlexLexer::yyFlexLex
- 如何使cmake输出到"build"目录?
- Go 是否支持调用C++函数?
- 使用Bazel C++教程;build不创建/使用共享库
- Android NDK.Build命令失败.未定义的引用.clang++:错误:链接器命令失败,退出代码为1
- "Build succeeded"但"The breakpoint will not currently be hit"
- build命令失败,外部原生问题android工作室
- Go/C++gRPC客户端通道和存根生命周期
- 是否有用于"go to variable type definition" C++中"auto"变量的 Visual Studio 键盘快捷方式?
- 指定 go build 的 C++ 版本
- 是否有一个示例如何使用SWIG生成GO Build的C Buidings