【问题标题】:Problem with compiling C code编译C代码的问题
【发布时间】:2011-07-07 22:33:01
【问题描述】:

我正在使用 Dev-C++ 4.9.9.2 和 MinGW 来编译这段代码:

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

  }

bool 返回目前没有意义,我想在编译时更改它。

【问题讨论】:

  • 在您的包含之前您似乎有问题。你能把这些部分贴出来吗?

标签: c compiler-errors mingw glibc dev-c++


【解决方案1】:

您不能只将几个头文件从 glibc 带到 windows 上的 mingw。这些头文件不是自包含的,它们需要很多其他头文件,甚至可能需要安装在系统上(不仅仅是在 glibc 源文件夹中引用..)

除此之外,glibc 不是为 windows 制作的——这些头文件是专门为 glibc 制作的,win32 也没有 getgrnam() 函数。 (你需要 cygwin,它有自己的头文件)

【讨论】:

  • 你知道是否有一种方法可以在不使用 getgrnam() 的情况下获取组中所有用户的列表(在 c 中)?
【解决方案2】:

在最底层的for循环中缺少一个大括号,但也许只是一个发布错误?

【讨论】:

    【解决方案3】:

    我怀疑这是问题的根源,但看起来你的 for 有一个右括号 },但缺少并打开一个。

    【讨论】:

      猜你喜欢
      • 2014-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      相关资源
      最近更新 更多