2016-09-12 50 views
0

我得到错误“./test.h:10:3:错误:未知类型名称'PROCESS'”当我包含我的头文件test.h具有结构定义PROCESS作为我的C的一部分Go Lang应用程序。该代码使用C编译没有问题,所以我想我做的事情很简单的错误...为什么CGo不能识别我在头文件中声明的结构?

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"); 

} 

test.h的含量低于...

#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; 

}; 

回答

2

在C, (与C++不同),struct关键字不会声明可以自己使用的类型名称;它需要使用struct关键字的资格。该类型是struct PROCESS不是PROCESS

struct PROCESS 
{ 
    char* name ; 
    int os_type ; 
    addr_t address ; 
    struct PROCESS* next ; // The struct keyword is needed here 
    ... 
+0

哇,这工作完美,谢谢你克利福德。我将C++重构为C以避免必须使用SWIG,甚至不知道这会是一个问题。谢谢。 – dimlee

相关问题