Join 136,582 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,922 people online right now. Registration is fast and FREE... Join Now!
Hi guys! I keep getting these errors: 1>main.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification 1>main.obj : error LNK2001: unresolved external symbol "enum HeuristicType g_heuristicType" (?g_heuristicType@@3W4HeuristicType@@A) 1>Pathfinder.obj : error LNK2001: unresolved external symbol "enum HeuristicType g_heuristicType" (?g_heuristicType@@3W4HeuristicType@@A) 1>.\Debug/Pathfinder.exe : fatal error LNK1120: 1 unresolved externals
Here's some of the code where I think the problem may be coming from
cpp
#pragma warning (disable:4786)
#include <windows.h> #include <time.h> #include <list> //need to include this for the toolbar stuff #include <commctrl.h> #pragma comment(lib, "comctl32.lib")
//------------------------- RedrawDisplay --------------------------------- // // Call this to refresh the client window //------------------------------------------------------------------------ void RedrawDisplay(HWND hwnd) { InvalidateRect(hwnd, NULL, TRUE); UpdateWindow(hwnd); }
//----------------------- ResizeToCorrectClientArea --------------------------- // // resizes the client are taking into account any toolbars and any menus //----------------------------------------------------------------------------- void ResizeToCorrectClientArea(HWND hwnd, int AccumulativeToolbarHeight, RECT ClientArea) {
//---------------------------- WindowProc --------------------------------- // // This is the callback function which handles all the windows messages //-------------------------------------------------------------------------
//A WM_CREATE msg is sent when your application window is first //created case WM_CREATE: { //seed random number generator srand((unsigned) time(NULL));
//---------------create a surface to render to(backbuffer)
//create a memory device context hdcBackBuffer = CreateCompatibleDC(NULL);
//get the DC for the front buffer HDC hdc = GetDC(hwnd);
//get the height of the toolbar RECT rectToolbar; GetWindowRect(g_hwndToolbar, &rectToolbar); ToolBarHeight = abs(rectToolbar.bottom - rectToolbar.top);
//let the toolbar know about the resize SendMessage(g_hwndToolbar, WM_SIZE, wParam, lParam);
//this defines the area to be redrawn (to prevent the toolbar flickering) GetClientRect(hwnd, &rectClientWindow); rectClientWindow.bottom = ClientHeight - ToolBarHeight - 1;
//create a memory device context hdcBackBuffer = CreateCompatibleDC(NULL);
//get the DC for the front buffer HDC hdc = GetDC(hwnd);
//fill the backbuffer with white BitBlt(hdcBackBuffer, 0, 0, cxClient, cyClient, NULL, NULL, NULL, WHITENESS);
gdi->StartDrawing(hdcBackBuffer);
g_Pathfinder->Render();
gdi->StopDrawing(hdcBackBuffer);
//now blit backbuffer to front BitBlt(ps.hdc, 0, 0, cxClient, cyClient, hdcBackBuffer, 0, 0, SRCCOPY);
EndPaint (hwnd, &ps);
}
break;
case WM_SIZE: { cxClient = LOWORD(lParam); cyClient = HIWORD(lParam);
//now to resize the backbuffer accordingly. First select //the old bitmap back into the DC SelectObject(hdcBackBuffer, hOldBitmap);
//don't forget to do this or you will get resource leaks DeleteObject(hBitmap);
//get the DC for the application HDC hdc = GetDC(hwnd);
//create another bitmap of the same size and mode //as the application hBitmap = CreateCompatibleBitmap(hdc, rectClientWindow.right, rectClientWindow.bottom);
ReleaseDC(hwnd, hdc);
//select the new bitmap into the DC SelectObject(hdcBackBuffer, hBitmap); }
break;
case WM_DESTROY: {
//clean up our backbuffer objects SelectObject(hdcBackBuffer, hOldBitmap);
// kill the application, this sends a WM_QUIT message PostQuitMessage (0); }
break;
}//end switch
//this is where all the messages not specifically handled by our //winproc are sent to be processed return DefWindowProc (hwnd, msg, wParam, lParam); }
//add the buttons to the toolbar SendMessage(hwndToolBar, TB_ADDBUTTONS, (WPARAM)NumButtons, (LPARAM)(LPTBBUTTON)&button);
return hwndToolBar; }
//-------------------------------- WinMain ------------------------------- // // The entry point of the windows program //------------------------------------------------------------------------ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) { //handle to our window HWND hWnd;
//our window class structure WNDCLASSEX winclass;
// first fill in the window class stucture winclass.cbSize = sizeof(WNDCLASSEX); winclass.style = CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hInstance; winclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1)); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = NULL; winclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); winclass.lpszClassName = g_szWindowClassName; winclass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
//register the window class if (!RegisterClassEx(&winclass)) { MessageBox(NULL, "Registration Failed!", "Error", 0);
//exit the application return 0; }
//create the window hWnd = CreateWindowEx (NULL, // extended style g_szWindowClassName, // window class name g_szApplicationName, // window caption WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU, // window style GetSystemMetrics(SM_CXSCREEN)/2 - WindowWidth/2, GetSystemMetrics(SM_CYSCREEN)/2 - WindowHeight/2, WindowWidth, // initial x size WindowHeight, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL); // creation parameters
//make sure the window creation has gone OK if(!hWnd) { MessageBox(NULL, "CreateWindowEx Failed!", "Error!", 0); }
//create the toolbar g_hwndToolbar = CreateToolBar(hWnd, hInstance);
#ifndef ASTAR_HEURISTIC_POLICIES_H #define ASTAR_HEURISTIC_POLICIES_H //----------------------------------------------------------------------------- // // Name: AStarHeuristicPolicies.h // // Author: Mat Buckland (www.ai-junkie.com) // // Desc: class templates defining a heuristic policy for use with the A* // search algorithm //----------------------------------------------------------------------------- #include "misc/utils.h" enum HeuristicType {Euclid, DistanceSquared, Manhattan}; extern HeuristicType g_heuristicType; //----------------------------------------------------------------------------- //the euclidian heuristic (straight-line distance) //----------------------------------------------------------------------------- class Heuristic { public:
Heuristic(){}
//calculate the straight line distance from node nd1 to node nd2 template <class graph_type> static double Calculate(const graph_type& G, int nd1, int nd2) { switch(g_heuristicType) { case Euclid: { return Vec2DDistance(G.GetNode(nd1).Pos(), G.GetNode(nd2).Pos()); } break;
case DistanceSquared: { return Vec2DDistanceSq(G.GetNode(nd1).Pos(), G.GetNode(nd2).Pos()); } break;
//----------------------------------------------------------------------------- //this uses the euclidian distance but adds in an amount of noise to the //result. You can use this heuristic to provide imperfect paths. This can //be handy if you find that you frequently have lots of agents all following //each other in single file to get from one place to another //----------------------------------------------------------------------------- class Heuristic_Noisy_Euclidian { public:
Heuristic_Noisy_Euclidian(){}
//calculate the straight line distance from node nd1 to node nd2 template <class graph_type> static double Calculate(const graph_type& G, int nd1, int nd2) { return Vec2DDistance(G.GetNode(nd1).Pos(), G.GetNode(nd2).Pos()) * RandInRange(0.9f, 1.1f); } };
//----------------------------------------------------------------------------- //you can use this class to turn the A* algorithm into Dijkstra's search. //this is because Dijkstra's is equivalent to an A* search using a heuristic //value that is always equal to zero. //----------------------------------------------------------------------------- class Heuristic_Dijkstra { public:
template <class graph_type> static double Calculate(const graph_type& G, int nd1, int nd2) { return 0; } };
#endif
I just can't seem to find what I'm doing wrong. Any help would be greatly appreciated. Thanks in advance! Please let me know if you need me to post more of the files.
Without even looking at your code, you can see the problem in your error list.
The build process has three steps (in order): 1) Preprocessor 2) Compiler 3) Linker
Anytime you see LNK in your error list, it means you have a Linker error. This indicates that something above main() is wrong. Most likely, either you're missing a file, or not including the right file (possibly a .h).
Now, with this new information, go through your code and see if you can fix your solution!
This post has been edited by Psionics: 5 Oct, 2008 - 07:12 PM
It doesn't appear that I've left out any files to be included.
I'm really green to programming so I'm at a loss for some things. For example, the warning about ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification, I have no idea as to what that means.
EDIT: Ok so I added #include <afxtempl.h> and it cleared up the linker issues but now I got another error: