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条)

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了