我想在C代码中调用go方法操作系统是Windows10我使用Cygwin64 Terminal
main.go
package main
import "C"
func main() {}
//export number_add_mod
func number_add_mod(a, b, mod C.int) C.int {
return (a + b) % mod
}
_ test_main.c
#include "number.h"
#include <stdio.h>
int main() {
int a = 10;
int b = 5;
int c = 12;
int x = number_add_mod(a, b, c);
printf("(%d+%d)%%%d = %d\n", a, b, c, x);
return 0;
}
当我跑步时
go build -buildmode=c-archive -o number.a
报告错误
# runtime/cgo
gcc_libinit_windows.c: in function‘x_cgo_sys_thread_create’:
gcc_libinit_windows.c:57:12: error:implicit declaration of function ‘_beginthread’; did you mean ‘OpenThread’? [-Werror=implicit-function-declaration]
thandle = _beginthread(func, 0, arg);
^~~~~~~~~~~~
OpenThread
cc1:
go: failed to remove work dir: GetFileInformationByHandle D:\cygwin64new\tmp\go-build109746670\NUL: Incorrect function.
make: *** [Makefile:5:default]
我安装了tdm-gcc解决的问题