LinKer Error for Static Function

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2009
Posts: 21
Reputation: vishalonne is an unknown quantity at this point 
Solved Threads: 0
vishalonne vishalonne is offline Offline
Newbie Poster

LinKer Error for Static Function

 
0
  #1
Jun 17th, 2009
Hi Every Body
I am new born in C++ I am facing and error for last 3 days I tried my best with all what I knew but FAILED.....
Error is -
" Linker Error: Undefined Symbol Library::code in module PRGDONE.CPP"
I am using Turbo C++ 3.0 of Borland

Here is the code -
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<iomanip.h>
  4. #include<process.h>
  5. #include<stdio.h>
  6. #include<stdlib.h>
  7. class library
  8. {
  9. int sum,total,choice ,no;
  10. static int code,a,c,p,m,d,e,h,f,z;
  11. public:
  12. void text()
  13. {
  14. while(no<121||no>125)
  15. {
  16. cout<<"\n enter the card no.between(121 to 125):";
  17. cin>>no;
  18. if(no<121||no>125)
  19. {
  20. cout<<"\n incorrect no.";
  21. cout<<"\n enter the card no. again:";
  22. }
  23. else
  24. {
  25. break;
  26. }
  27. }
  28. }
  29. void text1()
  30. {
  31. cout<<"\n\n"<<setw(39)<<" ------------ ";
  32. cout<<"\n\n"<<setw(39)<<" | LIBRARY | ";
  33. cout<<"\n\n"<<setw(39)<<" ------------ ";
  34. cout<<"\n\n\n"<<"1 BOOKS";
  35. cout<<"\n"<<"2 GET";
  36. cout<<"\n"<<"3 EXIST";
  37. cout<<"\n\n ENTER YOUR CHOICE::";
  38. cin>>choice;
  39. switch (choice)
  40. {
  41. case 1: cout<<"\n BOOKS DETAIL";
  42. cout<<"\n BOOK NAME CODE QUANTITY";
  43. cout<<"\n chemistry 1001 5";
  44. cout<<"\n panipath war 1002 5";
  45. cout<<"\n maths 1003 5";
  46. cout<<"\n develop personality 1004 5";
  47. cout<<"\n Computer advance 1005 5";
  48. cout<<"\n how to learn 1006 5";
  49. cout<<"\n Phycs today 1007 5";
  50. break;
  51. case 2: cout<<"\n BOOK AVAILABLE\n";
  52. total=35;
  53. cout<<" TOTAL BOOK THAT CAN BE ISSUED:";
  54. cout<<total<<endl;
  55. break;
  56. case 3: break;
  57. default: cout<<"\n YOU HAVE ENTERED WRONG VALUE";
  58. }
  59. }
  60. static void work()
  61. {
  62. while(code<1001 ||code>1007)
  63. {
  64. cout<<"\n ENTER THE CODE BETWEEN (1001 TO 1007)";
  65. cin>>code;
  66. if (code<1001 || code>1007)
  67. {
  68. cout<<"INVALID CODE(book not available)";
  69. }
  70. else
  71. {
  72. switch(code)
  73. {
  74. case 1001:
  75. for(c=1;c<=5;c++)
  76. {
  77. cout<<"\nbook available of code 1001:"<<c;
  78. }
  79. break;
  80. case 1002:
  81. for(p=1;p<=5;p++)
  82. {
  83. cout<<"\n book available of code 1002:"<<p;
  84. }
  85. break;
  86. case 1003:
  87. for(m=1;m<=5;m++)
  88. {
  89. cout<<"\n book available of code 1003:"<<m;
  90. }
  91. break;
  92. case 1004:
  93. for(d=1;d<=5;d++)
  94. {
  95. cout<<"\n book available of code 1004:"<<d;
  96. }
  97. break;
  98. case 1005:
  99. for(e=1;e<=5;e++)
  100. {
  101. cout<<"\n book available of code 1005:"<<e;
  102. }
  103. break;
  104. case 1006:
  105. for(h=1;h<=5;h++)
  106. {
  107. cout<<"\n book available of code 1006 :"<<h; }
  108. break;
  109. case 1007:
  110. for(f=1;f<=5;f++)
  111. {
  112. cout<<"\n book available of code 1007:"<<f;
  113. }
  114. break;
  115. }
  116. for(z=1;z<=5;z++)
  117. {
  118. cout<<"\n card holder issued book"<<z;
  119. }
  120. for(a=1;a>=35;a--)
  121. {
  122. cout<<"\ntotal no.of books available"<<a;
  123. }
  124. }
  125. }
  126. }
  127. };
  128. int library::a=0;
  129. int library::c=0;
  130. int library::p=0;
  131. int library::m=0;
  132. int library::d=0;
  133. int library::h=0;
  134. int library::f=0;
  135. int library::z=0;
  136. int library::e=0;
  137. void main()
  138. {
  139. clrscr();
  140. library l1;
  141. l1.text();
  142. l1.text1();
  143. library::work();
  144. getch();
  145. }
Please some body help me in removing this error....

Tnak you every body in Advance...........
Last edited by Ancient Dragon; Jun 17th, 2009 at 9:05 am. Reason: add code tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 672
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 99
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: LinKer Error for Static Function

 
0
  #2
Jun 17th, 2009
Welcome to Daniweb and Also to C++, Firstly Please Use CODE TAGS the next time you post in your question,

Firstly I see that you are Using a outdated compiler. Though it is not il-legal to use it . It is considered better if you use a modern compiler like CODE::BLOCKs etc.

Next Would you also specify at which line do you get that error, so it will be much easier to figure it out.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 21
Reputation: vishalonne is an unknown quantity at this point 
Solved Threads: 0
vishalonne vishalonne is offline Offline
Newbie Poster

Re: LinKer Error for Static Function

 
0
  #3
Jun 17th, 2009
Thank you for your reply its exactly not compilation error. Error is coming while running the program after compilation
" Linker Error: Undefined Symbol Library::code in module PRGDONE.CPP"
Line Number is not mentioned in error, but when I comment the line - library::work(); in main function then I get Success message

Please help me out.

Thank you
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: LinKer Error for Static Function

 
0
  #4
Jun 17th, 2009
>> static int code,a,c,p,m,d,e,h,f,z;

You forgot to declare code globally like you did the others
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 21
Reputation: vishalonne is an unknown quantity at this point 
Solved Threads: 0
vishalonne vishalonne is offline Offline
Newbie Poster

Re: LinKer Error for Static Function

 
0
  #5
Jun 17th, 2009
Dear Dragon
Thank you very very much for helping mebut now I am 3 compilation warings are coming on line no 14, 40, 63 errors are -
Functions containing while are not expanded inline
Functions containing switch are not expanded inline
Functions containing while are not expanded inline

respectively .
I will be thankfull to you for your kind cooperation

Regards
Vishal
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 792
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

Re: LinKer Error for Static Function

 
0
  #6
Jun 17th, 2009
A function defined inside a class is automatically request the compiler to make it inline:
  1. class foo
  2. {
  3. int f1()
  4. {
  5. //the definition
  6. // This function is inline
  7. }
  8. int f2();
  9. }
  10. int foo::f2()
  11. {
  12. //the definition goes here
  13. //function is not inline
  14. }
In above example f1 is inline while f2 is not.
In general, a inline function cannot contain loops or switch statements. Hence your compiler is making that warning.

Note that the style of your coding is 15 year old and is deprecated( I call such code as "rusted"). Sky Diploma is right in giving you advice to use a modern compiler ( I bet you would be using something as crappy as Turbo C++).
Please read this and migrate to standard.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,362
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: LinKer Error for Static Function

 
0
  #7
Jun 17th, 2009
Inlining is optional for compilers -- they may choose to honor it or not. Most compilers will honor one or two line inline functions, but the ones you posted are probably just too large to make inlining practical. IMO its better to put the implementation code for large functions in the *.cpp file instead of attempting to inline them.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 149
Reputation: monkey_king is on a distinguished road 
Solved Threads: 8
monkey_king monkey_king is offline Offline
Junior Poster

Re: LinKer Error for Static Function

 
1
  #8
Jun 17th, 2009
Originally Posted by Sky Diploma View Post
Firstly I see that you are Using a outdated compiler. Though it is not il-legal to use it . It is considered better if you use a modern compiler like CODE::BLOCKs etc.
I normally wont go into small errors in other peoples posting,
but it should be noted that code::blocks is an ide.
The compiler is most likely(depending on the setup) the mingw compiler. The mingw is a subset of the gnu toolchain.
I dont like being a correction nazi,
but the difference between compiler and ide/editor is quite important.
cheers!


To the original poster.

Is it nescesarry to use static variables for you program?
Last edited by monkey_king; Jun 17th, 2009 at 11:05 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC