mirror of
https://github.com/golang/go
synced 2024-11-18 06:14:46 -07:00
e45aebd6dd
When using -buildmode=c-archive or c-shared, and when installing packages that use cgo, and when those packages export some functions via //export comments, then for each such package, install a pkg.h header file that declares the functions. This permits C code to #include the header when calling the Go functions. This is a little awkward to use when there are multiple packages that export functions, as you have to "go install" your c-archive/c-shared object and then pull it out of the package directory. When compiling your C code you have to -I pkg/$GOOS_$GOARCH. I haven't thought of any more convenient approach. It's simpler when only the main package has exported functions. When using c-shared you currently have to use a _shared suffix in the -I option; it would be nice to fix that somehow. Change-Id: I5d8cf08914b7d3c2b194120c77791d2732ffd26e Reviewed-on: https://go-review.googlesource.com/9798 Reviewed-by: David Crawshaw <crawshaw@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
35 lines
650 B
C
35 lines
650 B
C
// Copyright 2015 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#include "p.h"
|
|
#include "libgo.h"
|
|
|
|
int main(void) {
|
|
int32_t res;
|
|
|
|
if (!DidInitRun()) {
|
|
fprintf(stderr, "ERROR: buildmode=c-archive init should run\n");
|
|
return 2;
|
|
}
|
|
|
|
if (DidMainRun()) {
|
|
fprintf(stderr, "ERROR: buildmode=c-archive should not run main\n");
|
|
return 2;
|
|
}
|
|
|
|
res = FromPkg();
|
|
if (res != 1024) {
|
|
fprintf(stderr, "ERROR: FromPkg()=%d, want 1024\n", res);
|
|
return 2;
|
|
}
|
|
|
|
CheckArgs();
|
|
|
|
fprintf(stderr, "PASS\n");
|
|
return 0;
|
|
}
|