Arn*_*rne 3 c++ swig build-system go
我想用“go build”来构建我的项目。我还没有找到任何有关如何将 swig 与 go 构建过程集成的文档。而且也很重要,它应该是一个C++例子 C很容易。
\n\n/* foo.i */\n%module foo\n%{\n#include "foo.h"\n%}\n%include "foo.h"\nRun Code Online (Sandbox Code Playgroud)\n\n#pragma once\nint foo(int a, int b);\nclass MyClass {\n int a,b,c;\npublic:\n MyClass(int a, int b, int c): a(a),b(b),c(c) {}\n int foo() {\n return (a+b)*c;\n }\n int bar() {\n return a*(b+c);\n }\n};\nRun Code Online (Sandbox Code Playgroud)\n\n#include "foo.h"\nint foo(int a, int b){\n return a*b;\n}\nRun Code Online (Sandbox Code Playgroud)\n\npackage foo\nimport "fmt"\nfunc main(args []string) {\n fmt.Println("Hello World!")\n fmt.Println(foo.foo(12, 17))\n}\nRun Code Online (Sandbox Code Playgroud)\n\narne@ad-X201t ~/g/s/g/k/swig-test> go build\n# github.com/krux02/swig-test\nIn file included from $WORK/github.com/krux02/swig-test/_obj/foo_wrap.c:194:0:\n./foo.h:5:1: Fehler: unbekannter Typname: \xc2\xbbclass\xc2\xab\n./foo.h:5:15: Fehler: expected \xc2\xbb=\xc2\xab, \xc2\xbb,\xc2\xab, \xc2\xbb;\xc2\xab, \xc2\xbbasm\xc2\xab or \xc2\xbb__attribute__\xc2\xab before \xc2\xbb{\xc2\xab token\n/tmp/go-build724218913/github.com/krux02/swig-test/_obj/foo_wrap.c: In Funktion \xc2\xbb_wrap_MyClass_set\xc2\xab:\n/tmp/go-build724218913/github.com/krux02/swig-test/_obj/foo_wrap.c:225:3: Fehler: unbekannter Typname: \xc2\xbbclass\xc2\xab\n/tmp/go-build724218913/github.com/krux02/swig-test/_obj/foo_wrap.c:226:3: Fehler: unbekannter Typname: \xc2\xbbclass\xc2\xab\n/tmp/go-build724218913/github.com/krux02/swig-test/_obj/foo_wrap.c:229:5: Fehler: unbekannter Typname: \xc2\xbbclass\xc2\xab\n[...]\nRun Code Online (Sandbox Code Playgroud)\n\n错误很明显,swig 尝试将所有内容构建为 C 库。
\n\n要测试它,只需复制:
\n\ngo get github.com/krux02/swig-test\nRun Code Online (Sandbox Code Playgroud)\n
查看添加了 Swig 支持的 bug 报告go build,看起来它决定如何根据文件扩展名编译 SWIG 包装器:
.swig文件被视为 C.swigcxx文件被视为 C++如果您重命名foo.swig为foo.swigcxx,它应该使用正确的 SWIG 标志和编译器。
| 归档时间: |
|
| 查看次数: |
3044 次 |
| 最近记录: |