我使用开发 - 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;
}
布尔返回目前没有意义,我想在编译作品时改变它。
看起来你有什么错** **之前的包括。你可以发布这些部分? – 2011-03-03 10:02:48