Search code examples
c++static-linking

Link Error with selfmade Lib


We are trying to build a Editor for our Game Engine and so we made a lib from the Engine und link that in the Editor Proj. The Path for the Lib and the Include Dir are remarked in the Proj. prop. I tryed it with and without WinAPI but the Link Error still remains. The Functions which are defined directly in the Header work, but the functions which are defined in the c++ files are creating the link errors. To i have to add the .cpp files in the Proj., isn't the lib exactly for that? -.-

OS: Windows 7 64Bit

Visual Studio 2010

#include "pch.h"

Application* g_pApp = NULL;

INT WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
BlocoApp blocoApp(&g_pApp);

// start engine
Editor mainForm;
if(!g_pApp->Init(L"Bloco", 1600, 900, true, hInstance))
{
    g_pApp->Exit();
    return 1;
}

// main loop
DXUTMainLoop();

g_pApp->Exit();

return 0;
}

The Compiler Error:

error LNK2001: Nicht aufgelöstes externes Symbol ""public: bool __thiscall Application::Init(class std::basic_string<unsigned short,struct std::char_traits<unsigned short>,class std::allocator<unsigned short> >,unsigned int,unsigned int,bool,struct HINSTANCE__ *,struct HWND__ *)" (?Init@Application@@QAE_NV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@II_NPAUHINSTANCE__@@PAUHWND__@@@Z)".

Solution

  • The Path for the Lib ... are remarked in the Proj. prop

    I suspect that you've configured the directory where the library is in the project's "Additional Library Directories" setting. That configures locations where the linker will look for library files it's been told to look for.

    However, you also need to tell the linker to actually include the library as an input file. This is done in the IDE using the "Input/Additional Dependencies" property.