Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
buildmode c-shared
/* Created by "go tool cgo" - DO NOT EDIT. */
/* package */
/* Start of preamble from import "C" comments. */
/* End of preamble from import "C" comments. */
/* Start of boilerplate cgo prologue. */
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;
/* End of boilerplate cgo prologue. */
#ifdef __cplusplus
extern "C" {
extern GoInt64 Test();
#ifdef __cplusplus
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 test.c
$ clang test.c -pedantic -Weverything -lfoo -L. -o foo -Wl,-rpath,.
#include <stdio.h>
#include "foo.h"
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