dooso0594 2012-09-25 22:05
浏览 68
已采纳

错误:从C构建示例时,无法确定C.stdout的名称种类? 走? CGO! 文章

I'm trying to build the following example from 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))
}

I'm running Go on Win7 64 and am using the 64 bit version of GCC from http://tdm-gcc.tdragon.net/ Running this on Linux isn't an option.

The error I get is:

could not determine kind of name for C.stdout

I haven't been able to find any documentation on this message, and very few hits show up on Google.

Does anyone have ideas on what's causing this? Thanks in advance!

  • 写回答

2条回答 默认 最新

  • dsajkdadsa14222 2012-09-26 05:47
    关注

    Here is one way to access C.stdout on windows:

    // 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?