| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 480 人关注过本帖
标题:TC Linker error,求解决
只看楼主 加入收藏
Incle
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-1-9
结帖率:100%
收藏
已结贴  问题点数:18 回复次数:4 
TC Linker error,求解决
连接时显示:“Linker error:Undefined symbol '_count'in module record.c”
我的count在record.h已经“extern int count;”声明过了。
以下为TC代码:
#include<record.h>
void main()
{ADDR *top;
 ASK(top);
 top->next=NULL;
 count=0;
 for(;;)handle_menu(top);
}


ADDR *input(ADDR *top)
{ADDR *p1,*p2;
 if(top->next==NULL)
   {p1=p2=(ADDR *)malloc(LEN);
    top=NULL;
    while(p1->name[0]!='0')
         {count+=1;
          if(count==1) top=p1;
          else p2->next=p1;
          p2=p1;
          p1=(ADDR *)malloc(LEN);
          printf("Please input your record:\n");
          printf("Name:");
          gets(p2->name);
          printf("Phonenumber:");
          gets(p2->tel);
         }
   }
 else
 {while(p1->name[0]!='0')
       {count+=1;
    p2->next=p1;
    p2=p1;
    p1=(ADDR *)malloc(LEN);
    printf("Please input your record:\n");
    printf("Name:");
    gets(p2->name);
    printf("Phonenumber:");
    gets(p2->tel);
       }
 }
 p1=p2;
 p2->next=NULL;
 return(top);
}

void display(ADDR*top)
{ADDR *p;
    printf("\nThere are %d records:\n",count);
 printf(" name  phonenumber\n");
 p=top;
 if(p!=NULL)
     do
     {printf("%6s %18s\n",p->name,p->tel);
      p=p->next;
     }while(p!=NULL);
 else printf("No list!\n");
}

void del(ADDR*top)
{int cn;
 char choose[20];
 ADDR *p1,*p2;
 if(count==0) printf("\n List null!\n");
 printf("Record delete:");
 printf("1.name.\n");
 printf("2.telephone number.\n");
 printf("Please enter the number:");
 gets(choose);
 while(1)
      {cn=atoi(choose);
       if(cn!=1&&cn!=2)
         {printf("Input error!Please choose 1-2 again:");
          gets(choose);
         }
       else break;
      }
 p1=top;
 switch(cn)
       {case 1:{while(strcmp(p1->name,choose)!=0)
             {p2=p1;
              p1=p1->next;
             }
        if(strcmp(p1->name,choose)==0)
          {if(p1==top) top=p1->next;
           else
           {p2->next=p1->next;
            p1=p2->next;
           }
           printf("Deleted.");
           count-=1;
          }
        else printf("Can't find the name!");
        if(count==0)
          {ASK(top);
           top->next=NULL;
          }
        p2=p1;
           }break;
    case 2:{while(strcmp(p1->tel,choose)==0)
             {p2=p1;
              p1=p1->next;
             }
        if(strcmp(p1->tel,choose)!=0)
          {if(p1==top)top=p1->next;
           else
           {p2->next=p1->next;
            p1=p2->next;
           }
           printf("Deleted.");
           count-=1;
          }
        else printf("Can't find the telephone number!");
        if(count==0)
          {ASK(top);
           top->next=NULL;
          }
        p2=p1;
           }break;
       }
}

int menu_select(void)
{int chose=0;
 printf("Menu\n");
 printf("1.Input a record.\n");
 printf("2.Delete a record.\n");
 printf("3.Display all records.\n");
 printf("4.Exit.\n");
 printf("Please enter the num:\n");
 scanf("%d",chose);
 return(chose);
}

void handle_menu(ADDR *top)
{switch(menu_select())
 {case 1:top=input(top);break;
  case 2:del(top);break;
  case 3:display(top);break;
  case 4:break;
  default:{printf("Error!please enter again.\n");switch(menu_select());}
 }
}

看了老半天,还是没找到问题所在-。-

搜索更多相关主题的帖子: include count 
2015-07-01 09:25
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:5 
连接时显示:“Linker error:Undefined symbol '_count'in module record.c
我的count在record.h已经“extern int count;”声明过了。

一个是.c一个是.h

大开眼界
2015-07-01 09:48
Incle
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-1-9
收藏
得分:0 
回复 2楼 lianyicq
就是说要在.c再声明一次?
2015-07-01 11:17
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:13 
extern只是声明,不是定义。声明是向编译器表明程序将使用一个名称如此的某类型变量,属于提前打招呼,但具体这个变量在哪里给出具体定义是未知的,当编译器发现这个声明时,执行编译是根据类型分配空间,但没有填入具体的内容,它必须在后期链接时找到定义的代码,才能填入正式的内容,但是你的程序自始至终没有给出这个定义,所以在链接时出错。这种情形跟声明了一个函数但没找到函数定义代码是一样的,都是Link阶段错误——链接阶段在编译阶段之后,严格说这不是编译错位,应叫链接错误。

授人以渔,不授人以鱼。
2015-07-01 14:46
Incle
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2015-1-9
收藏
得分:0 
回复 4楼 TonyDeng
明白了~谢谢
2015-07-01 18:07
快速回复:TC Linker error,求解决
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015511 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved