c - 编译C代码的问题

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

我使用 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 得到它们(也许这是错误的,但一个 friend 告诉我这是正确的方法))

当我尝试编译代码时,我在 glibc 的 header 中发现了一堆错误,例如:

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 return 目前没有意义,我想在编译作品时改变它。

最佳答案

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

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

关于c - 编译C代码的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5179132/

相关文章:

c - 如何区分子进程?

c - memcpy 段错误看似无害

unity3d - 错误(86,9): BCE0044: expecting EOF, found 'case'

python - 可以在没有 Visual Studio 的情况下使用 MinGw 编译 python.exe

c - cygwin 和 eclipse 的 sockets.h 问题

c++ - 使用 MinGW 对 DevIL 函数的 undefined reference

C 程序仅由于格式说明符而显示错误

c# - c dll 在 c# 项目中的使用

c++ - Wt 编译问题

c# - C#中的错误转换