1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 04:16:01 +00:00

ch2-{06|08}: 例子代码

This commit is contained in:
chai2010 2018-01-10 16:43:17 +08:00
parent 08d8c702d7
commit 2f3da52336
55 changed files with 1125 additions and 0 deletions

2
.gitignore vendored
View File

@ -24,6 +24,8 @@ _obj
# macOS
.DS_Store
*.a
*.lib
*.so
*.dll
*.obj

View File

@ -0,0 +1,20 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
cd mystring && make
go build -o a.out
LD_LIBRARY_PATH=$(shell pwd)/mystring ./a.out
macos:
cd mystring && make
go build -o a.out
DYLD_LIBRARY_PATH=$(shell pwd)/mystring ./a.out
windows:
# set path
clean:
-cd mystring && make clean
-rm *.a
-rm a.out

View File

@ -0,0 +1,22 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
//#cgo CFLAGS: -I./mystring
//#cgo LDFLAGS: -L${SRCDIR}/mystring -lmystring
//
//#include "mystring.h"
//#include <stdlib.h>
import "C"
import (
"fmt"
"unsafe"
)
func main() {
cs := C.make_string(C.CString("hello"))
defer C.free(unsafe.Pointer(cs))
fmt.Println(C.GoString(cs))
}

View File

@ -0,0 +1,8 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
gcc -shared -o libmystring.so mystring.c
clean:
-rm *.so

View File

@ -0,0 +1,26 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include "mystring.h"
#include <string.h>
static char buffer[1024];
static char* malloc(int size) {
return &buffer[0];
}
static void free(void* p) {
//
}
char* make_string(const char* s) {
char* p = malloc(strlen(s)+1);
strcpy(p, s);
return p;
}
void free_string(char* s) {
free(s);
}

View File

@ -0,0 +1,6 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
char* make_string(const char* s);
void free_string(char* s);

View File

@ -0,0 +1,20 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
go build -buildmode=c-archive -o number.a
gcc -o a.out _test_main.c number.a
./a.out
build_on_win64:
go build -buildmode=c-archive -o number.a
gcc -m64 -shared -o number-win64.dll number-win64.def number.a -Wl,--allow-multiple-definition -static -lstdc++ -lwinmm -lntdll -lWs2_32
lib /def:number-win64.def /machine:x64
build_with_vc:
cl -o a.out.exe _test_main.c number-win64.lib
clean:
-rm *.a *.lib
-rm a.out
-rm a.out.exe

View File

@ -0,0 +1,17 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include "number.h"
#include <stdio.h>
int main() {
int a = 10;
int b = 5;
int c = 12;
int x = number_add_mod(a, b, c);
printf("(%d+%d)%%%d = %d\n", a, b, c, x);
return 0;
}

View File

@ -0,0 +1,13 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
import "C"
func main() {}
//export number_add_mod
func number_add_mod(a, b, mod C.int) C.int {
return (a + b) % mod
}

View File

@ -0,0 +1,4 @@
LIBRARY number-win64.dll
EXPORTS
number_add_mod

View File

@ -0,0 +1,60 @@
/* Created by "go tool cgo" - DO NOT EDIT. */
/* package github.com/chai2010/advanced-go-programming-book/examples/ch2-06/make-clib-dll */
/* Start of preamble from import "C" comments. */
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"
#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H
typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
typedef struct { const char *p; GoInt n; } GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
#endif
/* End of boilerplate cgo prologue. */
#ifdef __cplusplus
extern "C" {
#endif
extern int number_add_mod(int p0, int p1, int p2);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,12 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
go build -buildmode=c-archive -o main.a
gcc -o a.out _test_main.c main.a
./a.out
clean:
-rm *.a *.lib
-rm a.out
-rm a.out.exe

View File

@ -0,0 +1,19 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include "main.h"
#include "./number/number.h"
#include <stdio.h>
int main() {
int a = 10;
int b = 5;
int c = 12;
int x = number_add_mod(a, b, c);
printf("(%d+%d)%%%d = %d\n", a, b, c, x);
goPrintln("done");
return 0;
}

View File

@ -0,0 +1,21 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
import "C"
import (
"fmt"
_ "github.com/chai2010/advanced-go-programming-book/examples/ch2-06/make-clib-from-multi-pkg/number"
)
func main() {
println("Done")
}
//export goPrintln
func goPrintln(s *C.char) {
fmt.Println("goPrintln:", C.GoString(s))
}

View File

@ -0,0 +1,60 @@
/* Created by "go tool cgo" - DO NOT EDIT. */
/* package github.com/chai2010/advanced-go-programming-book/examples/ch2-06/make-clib-from-multi-pkg */
/* Start of preamble from import "C" comments. */
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"
#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H
typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
typedef struct { const char *p; GoInt n; } GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
#endif
/* End of boilerplate cgo prologue. */
#ifdef __cplusplus
extern "C" {
#endif
extern void goPrintln(char* p0);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,11 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package number
import "C"
//export number_add_mod
func number_add_mod(a, b, mod C.int) C.int {
return (a + b) % mod
}

View File

@ -0,0 +1 @@
int number_add_mod(int a, int b, int mod);

View File

@ -0,0 +1,11 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
go build -buildmode=c-shared -o number.so
gcc -o a.out _test_main.c number.so
./a.out
clean:
-rm *.a
-rm a.out

View File

@ -0,0 +1,17 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include "number.h"
#include <stdio.h>
int main() {
int a = 10;
int b = 5;
int c = 12;
int x = number_add_mod(a, b, c);
printf("(%d+%d)%%%d = %d\n", a, b, c, x);
return 0;
}

View File

@ -0,0 +1,13 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
import "C"
func main() {}
//export number_add_mod
func number_add_mod(a, b, mod C.int) C.int {
return (a + b) % mod
}

View File

@ -0,0 +1,60 @@
/* Created by "go tool cgo" - DO NOT EDIT. */
/* package github.com/chai2010/advanced-go-programming-book/examples/ch2-06/make-clib-shared */
/* Start of preamble from import "C" comments. */
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"
#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H
typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
typedef struct { const char *p; GoInt n; } GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
#endif
/* End of boilerplate cgo prologue. */
#ifdef __cplusplus
extern "C" {
#endif
extern int number_add_mod(int p0, int p1, int p2);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,11 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
go build -buildmode=c-archive -o number.a
gcc -o a.out _test_main.c number.a
./a.out
clean:
-rm *.a
-rm a.out

View File

@ -0,0 +1,17 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include "number.h"
#include <stdio.h>
int main() {
int a = 10;
int b = 5;
int c = 12;
int x = number_add_mod(a, b, c);
printf("(%d+%d)%%%d = %d\n", a, b, c, x);
return 0;
}

View File

@ -0,0 +1,13 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
import "C"
func main() {}
//export number_add_mod
func number_add_mod(a, b, mod C.int) C.int {
return (a + b) % mod
}

View File

@ -0,0 +1,60 @@
/* Created by "go tool cgo" - DO NOT EDIT. */
/* package github.com/chai2010/advanced-go-programming-book/examples/ch2-06/use-clib-static */
/* Start of preamble from import "C" comments. */
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
#line 1 "cgo-gcc-export-header-prolog"
#ifndef GO_CGO_PROLOGUE_H
#define GO_CGO_PROLOGUE_H
typedef signed char GoInt8;
typedef unsigned char GoUint8;
typedef short GoInt16;
typedef unsigned short GoUint16;
typedef int GoInt32;
typedef unsigned int GoUint32;
typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
/*
static assertion to make sure the file is being used on architecture
at least with matching size of GoInt.
*/
typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
typedef struct { const char *p; GoInt n; } GoString;
typedef void *GoMap;
typedef void *GoChan;
typedef struct { void *t; void *v; } GoInterface;
typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
#endif
/* End of boilerplate cgo prologue. */
#ifdef __cplusplus
extern "C" {
#endif
extern int number_add_mod(int p0, int p1, int p2);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,8 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
go build -buildmode=plugin plugin.go -o plugin.so
clean:
-rm *.so

View File

@ -0,0 +1,23 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
import "plugin"
func main() {
p, err := plugin.Open("plugin.so")
if err != nil {
panic(err)
}
v, err := p.Lookup("V")
if err != nil {
panic(err)
}
f, err := p.Lookup("F")
if err != nil {
panic(err)
}
*v.(*int) = 7
f.(func())() // prints "Hello, number 7"
}

View File

@ -0,0 +1,15 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
// +build ignore
// +build go1.10
package main
import "fmt"
func main()
var V int
func F() { fmt.Printf("Hello, number %d\n", V) }

View File

@ -0,0 +1,20 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
cd number && make
go build -o a.out
LD_LIBRARY_PATH=$(shell pwd)/number ./a.out
macos:
cd number && make
go build -o a.out
DYLD_LIBRARY_PATH=$(shell pwd)/number ./a.out
windows:
# set path
clean:
-cd number && make clean
-rm *.a
-rm a.out

View File

@ -0,0 +1,15 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
//#cgo CFLAGS: -I./number
//#cgo LDFLAGS: -L${SRCDIR}/number -lnumber
//
//#include "number.h"
import "C"
import "fmt"
func main() {
fmt.Println(C.number_add_mod(10, 5, 12))
}

View File

@ -0,0 +1,8 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
gcc -shared -o libnumber.so number.c
clean:
-rm *.so

View File

@ -0,0 +1,5 @@
#include "number.h"
int number_add_mod(int a, int b, int mod) {
return (a+b)%mod;
}

View File

@ -0,0 +1 @@
int number_add_mod(int a, int b, int mod);

View File

@ -0,0 +1,11 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
cd number && make
go run main.go
clean:
-cd number && make clean
-rm *.a
-rm a.out

View File

@ -0,0 +1,15 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
//#cgo CFLAGS: -I./number
//#cgo LDFLAGS: -L${SRCDIR}/number -lnumber
//
//#include "number.h"
import "C"
import "fmt"
func main() {
fmt.Println(C.number_add_mod(10, 5, 12))
}

View File

@ -0,0 +1,10 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
gcc -c -o number.o number.c
ar rcs libnumber.a number.o
-rm *.o
clean:
-rm *.a *.o

View File

@ -0,0 +1,5 @@
#include "number.h"
int number_add_mod(int a, int b, int mod) {
return (a+b)%mod;
}

View File

@ -0,0 +1 @@
int number_add_mod(int a, int b, int mod);

View File

@ -0,0 +1,9 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
go build -o a.out
./a.out
clean:
-rm a.out

View File

@ -0,0 +1,13 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
//#cgo CFLAGS: -I./number
//#include "number.h"
import "C"
import "fmt"
func main() {
fmt.Println(C.number_add_mod(10, 5, 12))
}

View File

@ -0,0 +1,10 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
gcc -c -o number.o number.c
ar rcs libnumber.a number.o
-rm *.o
clean:
-rm *.a *.o

View File

@ -0,0 +1,5 @@
#include "number.h"
int number_add_mod(int a, int b, int mod) {
return (a+b)%mod;
}

View File

@ -0,0 +1 @@
int number_add_mod(int a, int b, int mod);

View File

@ -0,0 +1,4 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include "./number/number.c"

View File

@ -0,0 +1,8 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
default:
go run runme.go
clean:
-rm a.out

View File

@ -0,0 +1,8 @@
// Copyright © 2016 ChaiShushan (chaishushan{AT}gmail.com).
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include <iostream>
void SayHello() {
std::cout << "Hello, World!" << std::endl;
}

View File

@ -0,0 +1,8 @@
// Copyright © 2016 ChaiShushan (chaishushan{AT}gmail.com).
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
%module hello
%inline %{
extern void SayHello();
%}

View File

@ -0,0 +1,12 @@
// Copyright © 2016 ChaiShushan (chaishushan{AT}gmail.com).
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package hello
import (
"testing"
)
func TestSayHello(t *testing.T) {
SayHello()
}

View File

@ -0,0 +1,14 @@
// Copyright © 2016 ChaiShushan (chaishushan{AT}gmail.com).
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
// +build ignore
package main
import (
hello "."
)
func main() {
hello.SayHello()
}

View File

@ -0,0 +1,11 @@
# Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
# License: https://creativecommons.org/licenses/by-nc-sa/4.0/
# use go generate
default:
swig -go -cgo -intgosize 64 -o swig_wrap.cc hello.i
go run runme.go
clean:
-rm a.out

View File

@ -0,0 +1,8 @@
// Copyright © 2016 ChaiShushan (chaishushan{AT}gmail.com).
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
#include <iostream>
void SayHello() {
std::cout << "Hello, World!" << std::endl;
}

View File

@ -0,0 +1,73 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
* changes to this file unless you know what you are doing--modify the SWIG
* interface file instead.
* ----------------------------------------------------------------------------- */
// source: hello.i
package hello
/*
#define intgo swig_intgo
typedef void *swig_voidp;
#include <stdint.h>
typedef long long intgo;
typedef unsigned long long uintgo;
typedef struct { char *p; intgo n; } _gostring_;
typedef struct { void* array; intgo len; intgo cap; } _goslice_;
extern void _wrap_Swig_free_hello_679051ef4cde42b8(uintptr_t arg1);
extern uintptr_t _wrap_Swig_malloc_hello_679051ef4cde42b8(swig_intgo arg1);
extern void _wrap_SayHello_hello_679051ef4cde42b8(void);
#undef intgo
*/
import "C"
import "unsafe"
import _ "runtime/cgo"
import "sync"
type _ unsafe.Pointer
var Swig_escape_always_false bool
var Swig_escape_val interface{}
type _swig_fnptr *byte
type _swig_memberptr *byte
type _ sync.Mutex
func Swig_free(arg1 uintptr) {
_swig_i_0 := arg1
C._wrap_Swig_free_hello_679051ef4cde42b8(C.uintptr_t(_swig_i_0))
}
func Swig_malloc(arg1 int) (_swig_ret uintptr) {
var swig_r uintptr
_swig_i_0 := arg1
swig_r = (uintptr)(C._wrap_Swig_malloc_hello_679051ef4cde42b8(C.swig_intgo(_swig_i_0)))
return swig_r
}
func SayHello() {
C._wrap_SayHello_hello_679051ef4cde42b8()
}

View File

@ -0,0 +1,9 @@
// Copyright © 2016 ChaiShushan (chaishushan{AT}gmail.com).
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
%module hello
%inline %{
extern void SayHello();
%}

View File

@ -0,0 +1,14 @@
// Copyright © 2016 ChaiShushan (chaishushan{AT}gmail.com).
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
// +build ignore
package main
import (
hello "."
)
func main() {
hello.SayHello()
}

View File

@ -0,0 +1,257 @@
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 3.0.12
*
* This file is not intended to be easily readable and contains a number of
* coding conventions designed to improve portability and efficiency. Do not make
* changes to this file unless you know what you are doing--modify the SWIG
* interface file instead.
* ----------------------------------------------------------------------------- */
/* source: hello.i */
#define SWIGMODULE hello
/* -----------------------------------------------------------------------------
* This section contains generic SWIG labels for method/variable
* declarations/attributes, and other compiler dependent labels.
* ----------------------------------------------------------------------------- */
/* template workaround for compilers that cannot correctly implement the C++ standard */
#ifndef SWIGTEMPLATEDISAMBIGUATOR
# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
# define SWIGTEMPLATEDISAMBIGUATOR template
# elif defined(__HP_aCC)
/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
# define SWIGTEMPLATEDISAMBIGUATOR template
# else
# define SWIGTEMPLATEDISAMBIGUATOR
# endif
#endif
/* inline attribute */
#ifndef SWIGINLINE
# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
# define SWIGINLINE inline
# else
# define SWIGINLINE
# endif
#endif
/* attribute recognised by some compilers to avoid 'unused' warnings */
#ifndef SWIGUNUSED
# if defined(__GNUC__)
# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
# define SWIGUNUSED __attribute__ ((__unused__))
# else
# define SWIGUNUSED
# endif
# elif defined(__ICC)
# define SWIGUNUSED __attribute__ ((__unused__))
# else
# define SWIGUNUSED
# endif
#endif
#ifndef SWIG_MSC_UNSUPPRESS_4505
# if defined(_MSC_VER)
# pragma warning(disable : 4505) /* unreferenced local function has been removed */
# endif
#endif
#ifndef SWIGUNUSEDPARM
# ifdef __cplusplus
# define SWIGUNUSEDPARM(p)
# else
# define SWIGUNUSEDPARM(p) p SWIGUNUSED
# endif
#endif
/* internal SWIG method */
#ifndef SWIGINTERN
# define SWIGINTERN static SWIGUNUSED
#endif
/* internal inline SWIG method */
#ifndef SWIGINTERNINLINE
# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
#endif
/* exporting methods */
#if defined(__GNUC__)
# if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
# ifndef GCC_HASCLASSVISIBILITY
# define GCC_HASCLASSVISIBILITY
# endif
# endif
#endif
#ifndef SWIGEXPORT
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
# if defined(STATIC_LINKED)
# define SWIGEXPORT
# else
# define SWIGEXPORT __declspec(dllexport)
# endif
# else
# if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
# define SWIGEXPORT __attribute__ ((visibility("default")))
# else
# define SWIGEXPORT
# endif
# endif
#endif
/* calling conventions for Windows */
#ifndef SWIGSTDCALL
# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
# define SWIGSTDCALL __stdcall
# else
# define SWIGSTDCALL
# endif
#endif
/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
# define _CRT_SECURE_NO_DEPRECATE
#endif
/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
# define _SCL_SECURE_NO_DEPRECATE
#endif
/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
#endif
/* Intel's compiler complains if a variable which was never initialised is
* cast to void, which is a common idiom which we use to indicate that we
* are aware a variable isn't used. So we just silence that warning.
* See: https://github.com/swig/swig/issues/192 for more discussion.
*/
#ifdef __INTEL_COMPILER
# pragma warning disable 592
#endif
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
typedef long long intgo;
typedef unsigned long long uintgo;
# if !defined(__clang__) && (defined(__i386__) || defined(__x86_64__))
# define SWIGSTRUCTPACKED __attribute__((__packed__, __gcc_struct__))
# else
# define SWIGSTRUCTPACKED __attribute__((__packed__))
# endif
typedef struct { char *p; intgo n; } _gostring_;
typedef struct { void* array; intgo len; intgo cap; } _goslice_;
#define swiggo_size_assert_eq(x, y, name) typedef char name[(x-y)*(x-y)*-2+1];
#define swiggo_size_assert(t, n) swiggo_size_assert_eq(sizeof(t), n, swiggo_sizeof_##t##_is_not_##n)
swiggo_size_assert(char, 1)
swiggo_size_assert(short, 2)
swiggo_size_assert(int, 4)
typedef long long swiggo_long_long;
swiggo_size_assert(swiggo_long_long, 8)
swiggo_size_assert(float, 4)
swiggo_size_assert(double, 8)
#ifdef __cplusplus
extern "C" {
#endif
extern void crosscall2(void (*fn)(void *, int), void *, int);
extern char* _cgo_topofstack(void) __attribute__ ((weak));
extern void _cgo_allocate(void *, int);
extern void _cgo_panic(void *, int);
#ifdef __cplusplus
}
#endif
static char *_swig_topofstack() {
if (_cgo_topofstack) {
return _cgo_topofstack();
} else {
return 0;
}
}
static void _swig_gopanic(const char *p) {
struct {
const char *p;
} SWIGSTRUCTPACKED a;
a.p = p;
crosscall2(_cgo_panic, &a, (int) sizeof a);
}
#define SWIG_contract_assert(expr, msg) \
if (!(expr)) { _swig_gopanic(msg); } else
static void Swig_free(void* p) {
free(p);
}
static void* Swig_malloc(int c) {
return malloc(c);
}
extern void SayHello();
#ifdef __cplusplus
extern "C" {
#endif
void _wrap_Swig_free_hello_679051ef4cde42b8(void *_swig_go_0) {
void *arg1 = (void *) 0 ;
arg1 = *(void **)&_swig_go_0;
Swig_free(arg1);
}
void *_wrap_Swig_malloc_hello_679051ef4cde42b8(intgo _swig_go_0) {
int arg1 ;
void *result = 0 ;
void *_swig_go_result;
arg1 = (int)_swig_go_0;
result = (void *)Swig_malloc(arg1);
*(void **)&_swig_go_result = (void *)result;
return _swig_go_result;
}
void _wrap_SayHello_hello_679051ef4cde42b8() {
SayHello();
}
#ifdef __cplusplus
}
#endif