Skip to content

Instantly share code, notes, and snippets.

@bnagy bnagy/foo.h
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.