gpt4 book ai didi

go - 从 C 构建示例时出现错误 : Could not determine kind of name for C. stdout?去?加油!文章

转载 作者:IT王子 更新时间:2023-10-29 00:44:26 28 4
gpt4 key购买 nike

我正在尝试从 C? Go? Cgo! 构建以下示例:

package print

/*
#include <stdio.h>
#include <stdlib.h>
*/
import "C"
import "unsafe"

func Print(s string) {
cs := C.CString(s)
C.fputs(cs, (*C.FILE)(C.stdout))
C.free(unsafe.Pointer(cs))
}

我在 Win7 64 上运行 Go 并使用来自 http://tdm-gcc.tdragon.net/ 的 64 位版本的 GCC在 Linux 上运行它不是一种选择。

我得到的错误是:

could not determine kind of name for C.stdout

我找不到关于此消息的任何文档,而且在 Google 上显示的匹配项也很少。

有人知道是什么原因造成的吗?提前致谢!

最佳答案

这是在 Windows 上访问 C.stdout 的一种方法:

// Copyright 2009 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.

package stdio

/*
#include <stdio.h>
// on mingw, stderr and stdout are defined as &_iob[FILENO]
// on netbsd, they are defined as &__sF[FILENO]
// and cgo doesn't recognize them, so write a function to get them,
// instead of depending on internals of libc implementation.
FILE *getStdout(void) { return stdout; }
FILE *getStderr(void) { return stderr; }
*/
import "C"

var Stdout = (*File)(C.getStdout())
var Stderr = (*File)(C.getStderr())

https://github.com/golang/go/blob/master/misc/cgo/stdio/stdio.go

关于go - 从 C 构建示例时出现错误 : Could not determine kind of name for C. stdout?去?加油!文章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12591773/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com