[从C代码调用go库时隐式声明'_beginthread'函数

问题描述 投票:0回答:1

我想在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]
go gcc cgo
1个回答
0
投票

我安装了tdm-gcc解决的问题

http://tdm-gcc.tdragon.net/download/

© www.soinside.com 2019 - 2024. All rights reserved.