I need a linking confirmation

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: May 2007
Posts: 18
Reputation: sadaka is an unknown quantity at this point 
Solved Threads: 0
sadaka sadaka is offline Offline
Newbie Poster

I need a linking confirmation

 
0
  #1
Jul 13th, 2007
Hello everyone. Its been a while since I posted. I've gone through many threads regarding Linking issues that beginning programmers come across. Its the linking error - "error LNK2001 : unresolved external symbol." I admit I am a beginner and I also encounter the same problem. Going through all of the threads I became even more confused. I found no explicit details and the textbooks doesn't cover much of it either. Point is, I came up with a check list, my memory isn't as spiffy as it used to be so I hope that someone can confirm if I have it all correctly stated.
I use a Software Development Kit VC++6 Enterprise version ice-age.

1. I created a blank workspace and added an empty WIN32 windows application project.

2. I immediately go to Menu-Tool-Option and add all the includes, libs, and resources under the directories tab.

3. I then proceed to the coding and organized it as follows:
  • Placed the Class definitions in their respective source files
  • Placed the Class constructs in their respective header files
  • Created a header containment Header file that lists all include directives and any other pre-process directives
  • Create a source file that contains the WinMain and WindowProcedure functions
In the example below it demonstrate what I do in my projects-
I created a total of five files. 3 headers and 2 sources.

Headers:
  • Engine.h
  • HeaderIncludes.h
  • Main.h
Sources:
  • Engine.cpp
  • Main.cpp
In Engine.h-
  1. #include "HeaderIncludes.h"
In Main.h-
  1. #pragma once // Just in case it gets called twice somehow
  2. #include "HeaderIncludes.h"
  3. #include "Engine.h"
In HeaderInclude.h-
  1. #include <windows.h>
  2. #include <windowsx.h>
In Main.cpp-
  1. #include "Main.h"
  2. #include "Engine.h'
In Engine.cpp-
  1. #include "Engine.h"
Sorry, if it gets really long. HMMM, what do you guys think? Is it correct or am I forgetting some steps? Because I wanted to make sure that I'm doing it correctly so I don't get those linking errors ever again and as to boost my morale as a new programmer. Thank you all so very much in advance.
Last edited by sadaka; Jul 13th, 2007 at 4:02 am. Reason: corrected mispelled words
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 489
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: I need a linking confirmation

 
0
  #2
Jul 13th, 2007
That kind of error usually means you've missed out a definition somewhere - For example, if you've declared something in a header file, such as a function. Elsewhere in your code, you may have called that function, and the linker is unable to find the implementation to go with it.

Without seeing the code which exhibits the problem, there's no way to give any more information than that.
Last edited by Bench; Jul 13th, 2007 at 8:20 am.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 18
Reputation: sadaka is an unknown quantity at this point 
Solved Threads: 0
sadaka sadaka is offline Offline
Newbie Poster

Re: I need a linking confirmation

 
0
  #3
Jul 14th, 2007
Yes, you are absolutely correct Sir Bench. I did forget to declare a variable. I commend your brilliance with sound applaud. You are in concurrence to my checklist? Bravo, I knew I forgot something as so important as the dear variable itself. I have posted the code and indicated where I had forgotten. Oh and I posted another thread called, "Is there a way to end forever loops?" If you are interested in this thread please feel free. I am quite alright with sharing any of my codes. The rest are not really necessary but provides and idea of my setups. I made the WinMain and WindowProc as part of my class library. I still have to master manually creating a makefile, a dll and a def file. Although, I heard rumors that I would need to get an executable that will allow me to do so.

In Engine.cpp:
  1. #include "New01Main.h"
  2.  
  3. /*****************************************/
  4. RPGEngine *RPGEngine::cm_pEngine = NULL; // This is where I forgot to declare the variable
  5. /*****************************************/
  6.  
  7. LRESULT CALLBACK t1f_winprocedure(HWND hwnd, UINT umsg, WPARAM upperparam, LPARAM lowerparam)
  8. {
  9. return RPGEngine::ReleaseEngine()->cf_winproc(hwnd, umsg, upperparam, lowerparam);
  10. }
  11.  
  12. int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevi, LPTSTR szcmdline, int ishow)
  13. {
  14. MSG msg;
  15. static int iTrigger = 0;
  16.  
  17. if(AppInit(hinst))
  18. {
  19. if(!RPGEngine::ReleaseEngine()->InitMech(ishow))
  20. {
  21. return false;
  22. }
  23.  
  24. while(true)
  25. {
  26. if(PeekMessage(&msg, NULL, 0,0, PM_REMOVE))
  27. {
  28. if(msg.message == WM_QUIT)
  29. {
  30. TranslateMessage(&msg);
  31. DispatchMessage(&msg);
  32. break;
  33. }
  34. }
  35. else
  36. {
  37. AppIterate();
  38. TranslateMessage(&msg);
  39. DispatchMessage(&msg);
  40. }
  41. }//Close while
  42. //return (int)msg.wParam;
  43. return (int)msg.wParam;
  44. }//Close primary if statement
  45. //Support function
  46. AppEnd();
  47. return true;
  48. }//Close WinMain
  49.  
  50. //The constructor
  51. RPGEngine::RPGEngine(HINSTANCE hinst, LPTSTR classname, LPTSTR classtitle, WORD wicon, WORD wiconsm, int iwidth, int iheight)
  52. {
  53. cm_pEngine = this;//&cm_oEngine;
  54. cm_hinst = hinst;
  55. cm_hwnd = NULL;
  56.  
  57. //If there is a text string in the name copy it into class member
  58. if(lstrlen(classname)>0)
  59. {
  60. lstrcpy(cm_classname, classname);
  61. }
  62.  
  63. //If there is a text string in the title copy it into the class member
  64. if(lstrlen(classtitle)>0)
  65. {
  66. lstrcpy(cm_classtitle, classtitle);
  67. }
  68.  
  69. cm_wicon = wicon;
  70. cm_wiconsm = wiconsm;
  71. cm_iwidth = iwidth;
  72. cm_iheight = iheight;
  73. }
  74.  
  75. //The destructor
  76. RPGEngine::~RPGEngine()
  77. {
  78. }
  79.  
  80. bool RPGEngine::InitMech(int ishow)
  81. {
  82. wcx.cbSize = sizeof(wcx);
  83. wcx.style = CS_HREDRAW | CS_VREDRAW;
  84. wcx.lpfnWndProc = t1f_winprocedure;
  85. wcx.cbClsExtra = 0;
  86. wcx.cbWndExtra = 0;
  87. wcx.hInstance = cm_hinst;
  88. wcx.hIcon = LoadIcon(cm_hinst, MAKEINTRESOURCE(LeakIcon()));
  89. wcx.hIconSm = LoadIcon(cm_hinst, MAKEINTRESOURCE(LeakIconSm()));
  90. wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
  91. wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  92. wcx.lpszMenuName = NULL;
  93. wcx.lpszClassName = cm_classname;
  94.  
  95. //If register fails exit
  96. if(!RegisterClassEx(&wcx))
  97. {
  98. return false;
  99. }
  100.  
  101. int iWindowWidth = cm_iwidth + GetSystemMetrics(SM_CXFIXEDFRAME)*2, iWindowHeight = cm_iheight + GetSystemMetrics(SM_CYFIXEDFRAME)*2 + GetSystemMetrics(SM_CYCAPTION);
  102.  
  103. if(wcx.lpszMenuName != NULL)
  104. {
  105. iWindowHeight += GetSystemMetrics(SM_CYMENU);
  106. }
  107.  
  108. int iXWindowPos = (GetSystemMetrics(SM_CXSCREEN) - iWindowWidth)/2, iYWindowPos = (GetSystemMetrics(SM_CYSCREEN) - iWindowHeight)/2;
  109.  
  110. cm_hwnd = CreateWindow(cm_classname, cm_classtitle, WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX, iXWindowPos, iYWindowPos, iWindowWidth, iWindowHeight, NULL, NULL, cm_hinst, NULL);
  111.  
  112. if(!cm_hwnd)
  113. {
  114. return false;
  115. }
  116.  
  117. ShowWindow(cm_hwnd, ishow);
  118. UpdateWindow(cm_hwnd);
  119.  
  120. return true;
  121. }
  122.  
  123. LRESULT CALLBACK RPGEngine::cf_winproc(HWND hwnd, UINT umsg, WPARAM upperparam, LPARAM lowerparam)
  124. {
  125. switch(umsg)
  126. {
  127. case WM_CREATE:
  128. SetWindow(hwnd);
  129. //Support function
  130. AppStart(hwnd);
  131. return 0;
  132.  
  133. case WM_ACTIVATE:
  134. if(upperparam != WA_INACTIVE)
  135. {
  136. return 0;
  137. }
  138.  
  139. case WM_PAINT:
  140. HDC hdc;
  141. PAINTSTRUCT ps;
  142. hdc = BeginPaint(hwnd, &ps);
  143.  
  144. //Support function
  145. AppPaint(hdc);
  146.  
  147. EndPaint(hwnd, &ps);
  148. return 0;
  149.  
  150. case WM_DESTROY:
  151. //Support function
  152. AppEnd();
  153. PostQuitMessage(0);
  154. return 0;
  155. }
  156. return DefWindowProc(hwnd, umsg, upperparam, lowerparam);
  157. }
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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