Go实例代码:
package main
import (
"fmt"
)
import "C"
//export Printf
func Printf(format,str string) {
fmt.Printf(format,str)
}
func main(){}
编译命令:
go build -ldflags “-s -w” -buildmode=c-archive -o printf.a main.go
C代码实例:
#include "printf.h"
void main()
{
char fm[8]="Age:%s\n";
GoString format={fm,sizeof(fm)};
GoString values={"25",2};
Printf(format,values);
}
编译命令: linux 编译命令:gcc main.c printf.a -L. -o main -lpthread -s windows:编译命令:gcc -o main.exe 1.c libprint.a -lwinmm -lstdc++ -lws2_32 -lntdll 生成:main main.exe