Skip to content

Instantly share code, notes, and snippets.

@bnagy
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bnagy/eb2648248933826156c0 to your computer and use it in GitHub Desktop.
Save bnagy/eb2648248933826156c0 to your computer and use it in GitHub Desktop.
buildmode c-shared
/* Created by "go tool cgo" - DO NOT EDIT. */
/* package github.com/bnagy/cshared */
/* Start of preamble from import "C" comments. */
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
#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 __complex float GoComplex64;
typedef __complex double 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 { 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 GoInt64 Test();
#ifdef __cplusplus
}
#endif
package main
import "C"
// The export directive below doesn't work with a space between // and export!
//export Test
func Test() int64 {
return 42
}
func main() {}
$ ls
foo.h libfoo.so test.c
$ clang test.c -pedantic -Weverything -lfoo -L. -o foo -Wl,-rpath,.
#include <stdio.h>
#include "foo.h"
int
main() {
GoInt answer;
answer = Test();
printf("%lld\n", answer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment