0

I created a C++ solution full of WIN32 console application projects in the following form:

solution

Each projects contains .cpp and .h files and in Forms there is only main.cpp which includes the include lines for all .h files.

When trying to bulid even a single project i get LNK2019 - unresolved external symbol which seems to appear for each project when i try to compile from main.

I read many questions about it and i tried to deal with additional dependencies or Build order but nothing seems to make any difference.

I'm attaching the errors here for a single project (Button) - I guess that once i figure the issue with one project the rest will be same.

Error   1   error LNK2019: unresolved external symbol "public: void __thiscall Graphics::clearScreen(void)" (?clearScreen@Graphics@@QAEXXZ) referenced in function "public: virtual void __thiscall Button::keyDown(int,char)" (?keyDown@Button@@UAEXHD@Z)  D:\Forms\Button\Button.obj  Button
Error   2   error LNK2019: unresolved external symbol "public: void __thiscall Graphics::setBackground(enum Color)" (?setBackground@Graphics@@QAEXW4Color@@@Z) referenced in function "public: virtual void __thiscall Button::draw(class Graphics,int,int,unsigned int)" (?draw@Button@@UAEXVGraphics@@HHI@Z)  D:\Forms\Button\Button.obj  Button
Error   3   error LNK2019: unresolved external symbol "public: void __thiscall Graphics::setForeground(enum Color)" (?setForeground@Graphics@@QAEXW4Color@@@Z) referenced in function "public: virtual void __thiscall Button::draw(class Graphics,int,int,unsigned int)" (?draw@Button@@UAEXVGraphics@@HHI@Z)  D:\Forms\Button\Button.obj  Button
Error   4   error LNK2019: unresolved external symbol "public: void __thiscall Graphics::write(int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?write@Graphics@@QAEXHHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: virtual void __thiscall Button::draw(class Graphics,int,int,unsigned int)" (?draw@Button@@UAEXVGraphics@@HHI@Z)  D:\Forms\Button\Button.obj  Button
Error   5   error LNK2019: unresolved external symbol "public: __thiscall Control::Control(void)" (??0Control@@QAE@XZ) referenced in function "public: __thiscall Button::Button(int)" (??0Button@@QAE@H@Z) D:\Forms\Button\Button.obj  Button
Error   6   error LNK2019: unresolved external symbol "public: __thiscall Control::~Control(void)" (??1Control@@QAE@XZ) referenced in function __unwindfunclet$??0Button@@QAE@H@Z$0 D:\Forms\Button\Button.obj  Button
Error   7   error LNK2001: unresolved external symbol "public: virtual void __thiscall Control::getAllControls(class std::vector<class Control *,class std::allocator<class Control *> > *)" (?getAllControls@Control@@UAEXPAV?$vector@PAVControl@@V?$allocator@PAVControl@@@std@@@std@@@Z) D:\Forms\Button\Button.obj  Button
Error   8   error LNK2001: unresolved external symbol "public: virtual void __thiscall Control::setWidth(int)" (?setWidth@Control@@UAEXH@Z) D:\Forms\Button\Button.obj  Button
Error   9   error LNK2001: unresolved external symbol "public: virtual void __thiscall Control::setValue(int)" (?setValue@Control@@UAEXH@Z) D:\Forms\Button\Button.obj  Button
Error   10  error LNK2001: unresolved external symbol "public: virtual void __thiscall Control::SetForeground(enum Color)" (?SetForeground@Control@@UAEXW4Color@@@Z)    D:\Forms\Button\Button.obj  Button
Error   11  error LNK2001: unresolved external symbol "public: virtual void __thiscall Control::SetBackground(enum Color)" (?SetBackground@Control@@UAEXW4Color@@@Z)    D:\Forms\Button\Button.obj  Button
Error   12  error LNK2019: unresolved external symbol "public: void __thiscall Control::drawBackground(void)" (?drawBackground@Control@@QAEXXZ) referenced in function "public: virtual void __thiscall Button::draw(class Graphics,int,int,unsigned int)" (?draw@Button@@UAEXVGraphics@@HHI@Z) D:\Forms\Button\Button.obj  Button
Error   13  error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup   D:\Forms\Button\MSVCRTD.lib(crtexe.obj) Button
Error   14  error LNK1120: 13 unresolved externals  D:\Forms\Debug\Button.exe   Button

The .h files paths are correct and i can see all options in the intellisense.

I would appriciate any idea which might help me resolve this issue. Thanks

yishai
  • 83
  • 1
  • 3
  • 15
  • 1
    The error message is pretty straightforward. Find the function `Graphics::clearScreen` and include its file in the project you are trying to compile. – nwp Aug 18 '17 at 11:17
  • The .h file of this project (button) contains include instruction to Control.h and the button.cpp contains include to button.h. inside control.h there is include for Graphics.h – yishai Aug 18 '17 at 11:23
  • 1
    Did you add `Graphics.cpp` to the project? If you forget that then it will not be compiled and the functions will be known to exist (because of the header) but the implementation will be missing. – nwp Aug 18 '17 at 11:26
  • To which project do you mean? Graphics.cpp is part of the Graphics project – yishai Aug 18 '17 at 11:32
  • 1
    To the project you are currently compiling. Apparently you are currently trying to compile the Forms project and use Graphics functions, but the Forms project doesn't have the Graphics functions. A project must contain all the code it is using. – nwp Aug 18 '17 at 11:35
  • Thanks for the help. Arthur answered it correctly – yishai Aug 18 '17 at 11:46

1 Answers1

1

So if I understood correctly you have only one project with a main?

If that's right then try to build all your other projects as static libraries (.lib)(or shared libraies (.dll)) and reference them into your main project (Forms) it should be working.

Right now you are trying to build an executable (.exe) from 12other .exe. It can't work.

Arthur B
  • 36
  • 5
  • and we have a winner! Changed configuration type of each project except forms to lib and added reference to all these projects to Forms and it did the trick. thanks a lot – yishai Aug 18 '17 at 11:45