开发者

Problem with compiling C code

I'm using Dev-C++ 4.9.9.2 with MinGW to compile this code:

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

I included the following header files:

  • grp.h
  • sys/types.h

(got them from glibc 2.13 (maybe this is wrong, but a friend told me this is the right way))

when I try to compile the code, i get a bunch of errors in the headers from glibc, like:

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   

Edit:

This is the whole Code

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

  }

The bool return doesn't make sense at the moment, I want to change that when compiling works.


You can't just bring over a couple of header files from glibc over to mingw on windows. These header files are not self contained, they need a lot of other header files, and probably might even need to be installed on a system (not just refered to in the glibc source folders..)

Besides that, glibc isn't made for windows - these header files are crafted specifically for glibc, and win32 doesn't have the getgrnam() function anyway. (You'd need cygwin, which has its own header files)


There is a missing brace in the lowest for-loop, but maybe it is just a posting error?


I doubt this is the source of the problem, but it looks like your for has a closing bracket }, but lacks and opening one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜