title: can declared functions be called without a body
body: <p>Can you call a function that has no body but is declared in the header in your code?? Please read below for my situation.</p>
  
  <p>I am learning c++ so if my terminology is off then you know why. Any how, I am reading this book called "Advanced 2D Game Development" so if anyone's read the book then maybe they can help me out. In c++ he set 4 extern functions in Advanced2D.h</p>
  
  <pre><code>extern bool game_preload();
  extern bool game_init(HWND);
  extern void game_update();
  extern void game_end();
  </code></pre>
  
  <p>Later on down the line he calls on them several time's in a class but never gives them a body. What he is eventually trying to do with all the code is compile it into lib file so other projects could include it and actually use those 4 methods.</p>
  
  <p>He wanted me to go to the solutions properties/General/Output Directory and add this in both the Release and Debug Configuration</p>
  
  <pre><code>$(ProjectDir)..\lib\Advance2D.lib // It didn't work. Still added the libs at default location
  </code></pre>
  
  <p>Only to use those methods above in another project like this . This is when declarative methods get their bodies.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "..\Engine\Advanced2D.h"
  bool game_preload()
  {
       //display engine version in a message box
       g_engine-&gt;message(g_engine-&gt;getVersionText(), "TEST ENGINE");
       //return fail to terminate the engine
       return false;
  }
  
  bool game_init(HWND hwnd) { return 0;}
  void game_update() {}
  void game_end() {}
  </code></pre>
  
  <p>The only problem now is that I receive a linker error</p>
  
  <pre><code>1&gt;winmain.obj : error LNK2019: unresolved external symbol "bool __cdecl game_preload(void)" (?game_preload@@YA_NXZ) referenced in function _WinMain@16
  1&gt;c:\Engine\msvc8\Advance2D\Advance2D\..\lib\Advance2D.lib\Advance2D.exe : fatal error LNK1120: 1 unresolved externals
  </code></pre>
  
  <p>If I don't comment out those methods being used in the first project then the project never gets compiled ? </p>
  
  <p>The guy insist that I shouldn't receive any linker errors at the time of compiling it. And I quote the following</p>
  
  <blockquote>
    <p>Assuming you have typed the code into
    the specified files without any
    mistakes, you should be able to
    compile the engine project. There
    should be no dependencies for the
    engine because the compiler assumes
    that you will provide the needed libs
    at link time (when you create an
    executable using the engine’s lib).
    This is a rather complex issue that
    we’ll examine again over the next
    several chapters as we enhance the
    engine with new modules and
    functionality. You should not see any
    linker errors, only compiler errors if
    you have made a mistake while typing
    in the code.</p>
  </blockquote>
  
  <p>the following is advanced2D header</p>
  
  <pre><code>// Advanced2D Engine
  // Main header file
  #ifndef _ADVANCED2D_H
  #define _ADVANCED2D_H 1
  #include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  #include &lt;d3d9.h&gt;
  #include &lt;d3dx9.h&gt;
  #include &lt;dxerr.h&gt;
  #include "Timer.h"
  #define VERSION_MAJOR 1
  #define VERSION_MINOR 0
  #define REVISION 0
  
  #pragma comment(lib,"d3d9.lib")
  #pragma comment(lib,"d3dx9.lib")
  #pragma comment(lib, "winmm.lib")
  
  //external variables and functions
  extern bool gameover;
  extern bool game_preload();
  extern bool game_init(HWND);
  extern void game_update();
  extern void game_end();
  
  namespace Advanced2D
  {
      class Engine {
          private:
              int p_versionMajor, p_versionMinor, p_revision;
              HWND p_windowHandle;
              LPDIRECT3D9 p_d3d;
              LPDIRECT3DDEVICE9 p_device;
              LPDIRECT3DSURFACE9 p_backbuffer;
              LPD3DXSPRITE p_sprite_handler;
              std::string p_apptitle;
              bool p_fullscreen;
              int p_screenwidth;
              int p_screenheight;
              int p_colordepth;
              bool p_pauseMode;
              D3DCOLOR p_ambientColor;
              bool p_maximizeProcessor;
              Timer p_coreTimer;
              long p_frameCount_core;
              long p_frameRate_core;
              Timer p_realTimer;
              long p_frameCount_real;
              long p_frameRate_real;
          public:
              Engine();
              virtual ~Engine();
              int Init(int width, int height, int colordepth, bool fullscreen);
              void Close();
              void Update();
              void message(std::string message, std::string title = "ADVANCED 2D");
              void fatalerror(std::string message, std::string title = "FATAL ERROR");
              void Shutdown();
              void ClearScene(D3DCOLOR color);
              void SetDefaultMaterial();
              void SetAmbient(D3DCOLOR colorvalue);
              int RenderStart();
              int RenderStop();
              int Release();
              //accessor/mutator functions expose the private variables
              bool isPaused() { return this-&gt;p_pauseMode; }
              void setPaused(bool value) { this-&gt;p_pauseMode = value; }
              LPDIRECT3DDEVICE9 getDevice() { return this-&gt;p_device; }
              LPDIRECT3DSURFACE9 getBackBuffer() { return this-&gt;p_backbuffer; }
              LPD3DXSPRITE getSpriteHandler() { return this-&gt;p_sprite_handler; }
              void setWindowHandle(HWND hwnd) { this-&gt;p_windowHandle = hwnd; }
              HWND getWindowHandle() { return this-&gt;p_windowHandle; }
              std::string getAppTitle() { return this-&gt;p_apptitle; }
              void setAppTitle(std::string value) { this-&gt;p_apptitle = value; }
              int getVersionMajor() { return this-&gt;p_versionMajor; }
              int getVersionMinor() { return this-&gt;p_versionMinor; }
              int getRevision() { return this-&gt;p_revision; }
              std::string getVersionText();
              long getFrameRate_core() { return this-&gt;p_frameRate_core; };
              long getFrameRate_real() { return this-&gt;p_frameRate_real; };
              int getScreenWidth() { return this-&gt;p_screenwidth; }
              void setScreenWidth(int value) { this-&gt;p_screenwidth = value; }
              int getScreenHeight() { return this-&gt;p_screenheight; }
              void setScreenHeight(int value) { this-&gt;p_screenheight = value; }
              int getColorDepth() { return this-&gt;p_colordepth; }
              void setColorDepth(int value) { this-&gt;p_colordepth = value; }
              bool getFullscreen() { return this-&gt;p_fullscreen; }
              void setFullscreen(bool value) { this-&gt;p_fullscreen = value; }
              bool getMaximizeProcessor() { return this-&gt;p_maximizeProcessor; }
              void setMaximizeProcessor(bool value) { this-&gt;p_maximizeProcessor = value;}
      }; //class
  }; //namespace
  //define the global engine object (visible everywhere!)
  extern Advanced2D::Engine *g_engine;
  #endif
  </code></pre>
  
  <p>Advanced2d class </p>
  
  <pre><code>// Advanced2D Engine
  // Main source code file
  //includes
  #include "Advanced2D.h"
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;list&gt;
  #include "winmain.h"
  
  namespace Advanced2D
  {
      Engine::Engine()
      {
          srand((unsigned int)time(NULL));
          p_maximizeProcessor = false;
          p_frameCount_core = 0;
          p_frameRate_core = 0;
          p_frameCount_real = 0;
          p_frameRate_real = 0;
          p_ambientColor = D3DCOLOR_RGBA(255,255,255, 0);
          p_windowHandle = 0;
          p_pauseMode = false;
          p_versionMajor = VERSION_MAJOR;
          p_versionMinor = VERSION_MINOR;
          p_revision = REVISION;
          //set default values
          this-&gt;setAppTitle("Advanced2D");
          this-&gt;setScreenWidth(640);
          this-&gt;setScreenHeight(480);
          this-&gt;setColorDepth(32);
          this-&gt;setFullscreen(false);
          //window handle must be set later on for DirectX!
          this-&gt;setWindowHandle(0);
      }
  
      Engine::~Engine()
      {
          if (this-&gt;p_device) this-&gt;p_device-&gt;Release();
          if (this-&gt;p_d3d) this-&gt;p_d3d-&gt;Release();
      }
  
      std::string Engine::getVersionText()
      {
          std::ostringstream s;
          s &lt;&lt; "Advanced2D Engine v" &lt;&lt; p_versionMajor &lt;&lt; "." &lt;&lt; p_versionMinor
          &lt;&lt; "." &lt;&lt; p_revision;
          return s.str();
      }
  
      void Engine::message(std::string message, std::string title)
      {
          MessageBox(0, message.c_str(), title.c_str(), 0);
      }
  
      void Engine::fatalerror(std::string message, std::string title)
      {
          this-&gt;message(message,title);
          Shutdown();
      }
  
      int Engine::Init(int width, int height, int colordepth, bool fullscreen)
      {
          //initialize Direct3D
  
          this-&gt;p_d3d = Direct3DCreate9(D3D_SDK_VERSION);
  
          if (this-&gt;p_d3d == NULL) {
              return 0;
          }
  
          //get system desktop color depth
          D3DDISPLAYMODE dm;
          this-&gt;p_d3d-&gt;GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &amp;dm);
  
          //set configuration options for Direct3D
          D3DPRESENT_PARAMETERS d3dpp;
          ZeroMemory(&amp;d3dpp, sizeof(d3dpp));
          d3dpp.Windowed = (!fullscreen);
          d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
          d3dpp.EnableAutoDepthStencil = TRUE;
          d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
          d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
          d3dpp.BackBufferFormat = dm.Format;
          d3dpp.BackBufferCount = 1;
          d3dpp.BackBufferWidth = width;
          d3dpp.BackBufferHeight = height;
          d3dpp.hDeviceWindow = p_windowHandle;
  
          //create Direct3D device
          this-&gt;p_d3d-&gt;CreateDevice(
          D3DADAPTER_DEFAULT,
          D3DDEVTYPE_HAL,
          this-&gt;p_windowHandle,
          D3DCREATE_HARDWARE_VERTEXPROCESSING,
          &amp;d3dpp,
          &amp;this-&gt;p_device);
          if (this-&gt;p_device == NULL) return 0;
  
          //clear the backbuffer to black
          this-&gt;ClearScene(D3DCOLOR_XRGB(0,0,0));
  
          //create pointer to the back buffer
          this-&gt;p_device-&gt;GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &amp;this-&gt;p_backbuffer);
  
          //use ambient lighting and z-buffering
          this-&gt;p_device-&gt;SetRenderState(D3DRS_ZENABLE, TRUE);
          this-&gt;p_device-&gt;SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
          this-&gt;SetAmbient(this-&gt;p_ambientColor);
  
          //initialize 2D renderer
          HRESULT result = D3DXCreateSprite(this-&gt;p_device, &amp;this-&gt;p_sprite_handler);
          if (result != D3D_OK) return 0;
          //call game initialization extern function
          //if (!game_init(this-&gt;getWindowHandle())) return 0;
          //set a default material
          SetDefaultMaterial();
          return 1;
      }
  
  
      void Engine::SetDefaultMaterial()
      {
          D3DMATERIAL9 mat;
          memset(&amp;mat, 0, sizeof(mat));
          mat.Diffuse.r = 1.0f;
          mat.Diffuse.g = 1.0f;
          mat.Diffuse.b = 1.0f;
          mat.Diffuse.a = 1.0f;
          p_device-&gt;SetMaterial(&amp;mat);
      }
  
      void Engine::ClearScene(D3DCOLOR color)
      {
          this-&gt;p_device-&gt;Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
          color, 1.0f, 0);
      }
  
      void Engine::SetAmbient(D3DCOLOR colorvalue)
      {
          this-&gt;p_ambientColor = colorvalue;
          this-&gt;p_device-&gt;SetRenderState(D3DRS_AMBIENT, this-&gt;p_ambientColor);
      }
      int Engine::RenderStart()
      {
          if (!this-&gt;p_device) return 0;
          if (this-&gt;p_device-&gt;BeginScene() != D3D_OK) return 0;
          return 1;
      }
      int Engine::RenderStop()
      {
          if (!this-&gt;p_device) return 0;
          if (this-&gt;p_device-&gt;EndScene() != D3D_OK) return 0;
          if (p_device-&gt;Present(NULL, NULL, NULL, NULL) != D3D_OK) return 0;
          return 1;
      }
  
      void Engine::Shutdown()
      {
          gameover = true;
      }
  
      void Engine::Update()
      {
          static Timer timedUpdate;
          //calculate core framerate
          p_frameCount_core++;
          if (p_coreTimer.stopwatch(999)) {
          p_frameRate_core = p_frameCount_core;
          p_frameCount_core = 0;
          }
          //fast update with no timing
          game_update();
  
          //update with 60fps timing
          if (!timedUpdate.stopwatch(14)) {
              if (!this-&gt;getMaximizeProcessor())
              {
                  Sleep(1);
              }
          }
          else {
              //calculate real framerate
              p_frameCount_real++;
  
              if (p_realTimer.stopwatch(999)) {
                  p_frameRate_real = p_frameCount_real;
                  p_frameCount_real = 0;
              }
              //begin rendering
              this-&gt;RenderStart();
              //done rendering
              this-&gt;RenderStop();
          }
      }
      void Engine::Close()
      {
          game_end();
      }
  } //namespace
  </code></pre>
  
  <p>And here is the WinMain</p>
  
  <pre><code>#include &lt;sstream&gt;
  #include "winmain.h"
  #include "Advanced2D.h"
  //macro to read the key states
  #define KEY_DOWN(vk) ((GetAsyncKeyState(vk) &amp; 0x8000)?1:0)
  HINSTANCE g_hInstance;
  HWND g_hWnd;
  int g_nCmdShow;
  //declare global engine object
  Advanced2D::Engine *g_engine;
  bool gameover;
  
  
  //window event callback function
  LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  {
      switch( msg )
      {
      case WM_QUIT:
      case WM_CLOSE:
      case WM_DESTROY:
      gameover = true;
      break;
      }
      return DefWindowProc( hWnd, msg, wParam, lParam );
  }
  int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int
  nCmdShow)
  {
      MSG msg;
      srand((unsigned int)time(NULL));
      g_hInstance = hInstance;
      g_nCmdShow = nCmdShow;
      DWORD dwStyle, dwExStyle;
      RECT windowRect;
      /**
      * Create engine object first!
      **/
      g_engine = new Advanced2D::Engine();
      //let main program have a crack at things before window is created
      if (!game_preload()) {
          MessageBox(g_hWnd, "Error in game preload!", "Error", MB_OK);
          return 0;
      }
      //get window caption string from engine
      char title[255];
      sprintf_s(title, "%s", g_engine-&gt;getAppTitle().c_str());
      //set window dimensions
      windowRect.left = (long)0;
      windowRect.right = (long)g_engine-&gt;getScreenWidth();
      windowRect.top = (long)0;
      windowRect.bottom = (long)g_engine-&gt;getScreenHeight();
      //create the window class structure
      WNDCLASSEX wc;
      wc.cbSize = sizeof(WNDCLASSEX);
      //fill the struct with info
      wc.style = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc = (WNDPROC)WinProc;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = NULL;
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = NULL;
      wc.lpszMenuName = NULL;
      wc.lpszClassName = title;
      wc.hIconSm = NULL;
      //set up the window with the class info
      RegisterClassEx(&amp;wc);
      //set up the screen in windowed or fullscreen mode?
      if (g_engine-&gt;getFullscreen())
      {
          DEVMODE dm;
          memset(&amp;dm, 0, sizeof(dm));
          dm.dmSize = sizeof(dm);
          dm.dmPelsWidth = g_engine-&gt;getScreenWidth();
          dm.dmPelsHeight = g_engine-&gt;getScreenHeight();
          dm.dmBitsPerPel = g_engine-&gt;getColorDepth();
          dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
          if (ChangeDisplaySettings(&amp;dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
          MessageBox(NULL, "Display mode failed", NULL, MB_OK);
          g_engine-&gt;setFullscreen(false);
          }
          dwStyle = WS_POPUP;
          dwExStyle = WS_EX_APPWINDOW;
          ShowCursor(FALSE);
          }
          else {
          dwStyle = WS_OVERLAPPEDWINDOW;
          dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
          }
          //adjust window to true requested size
          AdjustWindowRectEx(&amp;windowRect, dwStyle, FALSE, dwExStyle);
          //create the program window
          g_hWnd = CreateWindowEx( 0,
          title, //window class
          title, //title bar
          dwStyle | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
          0, 0, //x,y coordinate
          windowRect.right - windowRect.left, //width of the window
          windowRect.bottom - windowRect.top, //height of the window
          0, //parent window
          0, //menu
          g_hInstance, //application instance
          0); //window parameters
          //was there an error creating the window?
          if (!g_hWnd) {
          MessageBox(g_hWnd, "Error creating program window!", "Error", MB_OK);
          return 0;
      }
      //display the window
      ShowWindow(g_hWnd, g_nCmdShow);
      UpdateWindow(g_hWnd);
      //initialize the engine
      g_engine-&gt;setWindowHandle(g_hWnd);
      if (!g_engine-&gt;Init(g_engine-&gt;getScreenWidth(), g_engine-&gt;getScreenHeight(),
      g_engine-&gt;getColorDepth(), g_engine-&gt;getFullscreen())) {
      MessageBox(g_hWnd, "Error initializing the engine", "Error", MB_OK);
      return 0;
      }
      // main message loop
      gameover = false;
      while (!gameover)
      {
          while (PeekMessage(&amp;msg, NULL, 0, 0, PM_REMOVE))
          {
              TranslateMessage(&amp;msg);
              DispatchMessage(&amp;msg);
          }
          g_engine-&gt;Update();
      }
  
      if (g_engine-&gt;getFullscreen()) {
          ShowCursor(TRUE);
      }
      g_engine-&gt;Close();
      delete g_engine;
      return 1;
  }
  </code></pre>