2011-03-03 124 views
1

我使用開發 - C++ 4.9.9.2使用MinGW編譯的代碼:問題的編譯C代碼

/* get the information about the group. */ 
    struct group* group_info = getgrnam("PLACEHOLDER"); 
    /* make sure this group actually exists. */ 

    if (!group_info) { 
    printf("group 'PLACEHOLDER' does not exist.\n"); 
    } 
    else 
    { 
    char** p_member; 

    printf("Here are the members of group 'PLACEHOLDER':\n"); 
    for (p_member = group_info->gr_mem; *p_member; p_member++) 
     printf(" %s\n", *p_member); 
    } 
    } 

我包括下面的頭文件:

  • grp.h
  • sys/types.h

(讓他們從glibc 2.13(也許這是錯誤的,但朋友告訴我這是正確的方式))

當我嘗試編譯代碼時,我得到了一堆錯誤的在從glibc的頭,如:

12 C:\glibc-2.9\include\sys\cdefs.h expected constructor, destructor, or type conversion before '(' token 
12 C:\glibc-2.9\include\sys\cdefs.h expected `,' or `;' before '(' token 
4 C:\glibc-2.9\include\grp.h expected constructor, destructor, or type conversion before '(' token 

編輯:

這是整個代碼

#include <grp.h> /* defines 'struct group', and getgrnam(). */ 
#include <sys/types.h> /* defines 'gid_t', etc.    */ 

BOOL getListOfGroupMembers() { 

    /* get the information about the "strange" group. */ 
    struct group* group_info = getgrnam("PLACEHOLDER"); 
    /* make sure this group actually exists. */ 
    if (!group_info) { 
     printf("group 'PLACEHOLDER' does not exist.\n"); 
    } 
    else 
    { 
     char** p_member; 

     printf("Here are the members of group 'PLACEHOLDER':\n"); 
     for (p_member = group_info->gr_mem; *p_member; p_member++) 
     { 
     printf(" %s\n", *p_member); 
     } 
    } 

    return 0; 

    } 

布爾返回目前沒有意義,我想在編譯作品時改變它。

+0

看起來你有什麼錯** **之前的包括。你可以發佈這些部分? – 2011-03-03 10:02:48

回答

0

有最低for循環,但也許它只是一個發佈錯誤缺少支柱?

2

你不能只是把過了幾個頭文件從glibc的到MinGW的Windows上。這些頭文件不是獨立包含的,它們需要很多其他頭文件,甚至可能需要安裝在系統上(不僅僅是指glibc源文件夾中)。

除此之外,glibc isn不適用於windows - 這些頭文件是專爲glibc製作的,而win32無論如何都沒有getgrnam()函數。 (你會需要Cygwin的,它有自己的頭文件)

+0

您是否知道是否有方法可以在不使用getgrnam()的情況下獲取組(c)中的所有用戶列表? – Templin 2011-03-03 10:21:45

0

我懷疑這是問題的根源,但它看起來像你換了一個右括號},但是缺乏開放一個。