以下转自:http://blog.csdn.net/koalazoo/archive/2004/12/26/229559.aspx 出现这个问题的原因一般是结构体未定义。 http://community.csdn.net/Expert/TopicView.asp?id=3669686 这里有一个例子,因为宏未定义,所以结构未正确定义,所以编译的时候出现上述错误。 ---------------------------------------- A: 我的一段程序老是出现编译错误,我不知道该怎么修改,请各位高手予以指点: /* File: private.c */ #include #include #include #include int main(int argc, char* argv[]) { int queue_id; struct msgbuf *msg; struct msgbuf *recv_msg; int rc; //建立消息队列 queue_id = msgget(IPC_PRIVATE, IPC_CREAT | 0600); if (queue_id == -1) { perror("main: msgget"); exit(1); } printf("message queue created, queue id '%d'./n", queue_id); //创建消息结构 msg = (struct msgbuf*)malloc(sizeof(struct msgbuf) +strlen("hello world")); msg->mtype = 1; strcpy(msg->mtext, "hello world"); //发送消息 rc = msgsnd(queue_id, msg, strlen(msg->mtext)+1, 0); if (rc == -1) { perror("main: msgsnd"); exit(1); } free(msg); printf("message placed on the queue successfully./n"); //接收消息 recv_msg = (struct msgbuf*)malloc(sizeof(struct msgbuf) +strlen("hello world")); rc = msgrcv(queue_id, recv_msg, strlen("hello world")+1, 0, 0); if (rc == -1) { perror("main: msgrcv"); exit(1); } printf("msgrcv: received message: mtype '%d'; mtext '%s'/n", recv_msg->mtype, recv_msg->mtext); return 0; } 显示26行:msg->mtype = 1; :dereferencing pointer to incomplete type! 该怎么解决? 解决: B: 在#include 那行前面加一句,像这样: #define __USE_GNU #include 这样再编译就OK了。 这是因为某种原因,__USE_GNU没定义,导致msgbuf这个结构没定义,所以编译的时候说这个结构没有实现。 打开msg.h看看就知道了。 A: 谢谢,果然是一个宏没有加进去,太疏忽了 谢谢你们 ----------------------------------------
dereferencing pointer to incomplete type
最新推荐文章于 2018-12-13 22:42:49 发布