doupo5861 2016-09-12 18:35
浏览 152
已采纳

CGo为什么不能识别我在头文件中声明的结构?

I am getting the error "./test.h:10:3: error: unknown type name 'PROCESS'" when I include my header file test.h that has the struct definition PROCESS as a part of my C Go Lang application. The code compiles in C with no problems so I imagine I'm doing something very simple incorrectly...

package main

// #include <sys/mman.h>
// #include <errno.h>
// #include <inttypes.h>
// #include <stdlib.h>
// #include "test.h"
import "C"

import (
    "fmt"
    _"unsafe"
  )


func main() {
    fmt.Println("Retrieving process list");

}

The contents of test.h are below...

#include <sys/mman.h>
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>

struct PROCESS {
    char *name;
    int os_type;
    addr_t address;
    PROCESS *next;

    //fields we care about
    unsigned int uid;
    unsigned int gid;
    unsigned int is_root;
    unsigned int io_r;
    unsigned int io_wr;
    unsigned int io_sys_r;
    unsigned int io_sys_wr;
    unsigned int used_super;
    unsigned int is_k_thread;
    unsigned int cpus;
    unsigned long hw_rss;
    unsigned long vma_size;
    unsigned long map_count;
    unsigned long pages;
    unsigned long total_map;
    unsigned long min_flt;
    unsigned long mm_usrs;
    unsigned long nr_ptes;
    unsigned long nvcsw;

};
  • 写回答

1条回答 默认 最新

  • dpdkqls6399 2016-09-12 18:45
    关注

    In C, (unlike C++), the struct keyword does not declare a type-name that can be used on its own; it needs qualification with the struct keyword. The type is struct PROCESS not PROCESS:

    struct PROCESS 
    {
        char* name ;
        int os_type ;
        addr_t address ;
        struct PROCESS* next ;   // The struct keyword is needed here
        ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败