943,511 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1200
  • C++ RSS
Jun 17th, 2009
0

LinKer Error for Static Function

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
vishalonne is offline Offline
69 posts
since Jun 2009
Jun 17th, 2009
0

Re: LinKer Error for Static Function

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.
Reputation Points: 673
Solved Threads: 125
Practically a Posting Shark
Sky Diploma is offline Offline
818 posts
since Mar 2008
Jun 17th, 2009
0

Re: LinKer Error for Static Function

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
vishalonne is offline Offline
69 posts
since Jun 2009
Jun 17th, 2009
0

Re: LinKer Error for Static Function

>> static int code,a,c,p,m,d,e,h,f,z;

You forgot to declare code globally like you did the others
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,945 posts
since Aug 2005
Jun 17th, 2009
0

Re: LinKer Error for Static Function

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
vishalonne is offline Offline
69 posts
since Jun 2009
Jun 17th, 2009
0

Re: LinKer Error for Static Function

A function defined inside a class is automatically request the compiler to make it inline:
cpp Syntax (Toggle Plain Text)
  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.
Reputation Points: 1486
Solved Threads: 140
Practically a Posting Shark
siddhant3s is offline Offline
816 posts
since Oct 2007
Jun 17th, 2009
0

Re: LinKer Error for Static Function

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,945 posts
since Aug 2005
Jun 17th, 2009
1

Re: LinKer Error for Static Function

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.
Reputation Points: 70
Solved Threads: 9
Junior Poster
monkey_king is offline Offline
160 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Which is faster/more efficient c++´s fstream, or c's FILE
Next Thread in C++ Forum Timeline: Read function from text file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC