简体   繁体   English

许多项目的解决方案上的C ++链接错误

[英]C++ link errors on solution with many projects

I created a C++ solution full of WIN32 console application projects in the following form: 我以以下形式创建了一个完整的WIN32控制台应用程序项目的C ++解决方案:

解

Each projects contains .cpp and .h files and in Forms there is only main.cpp which includes the include lines for all .h files. 每个项目都包含.cpp和.h文件,并且在Forms中只有main.cpp,其中包括所有.h文件的包含行。

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. 当尝试建立甚至一个项目时,我都会得到LNK2019-无法解析的外部符号,当我尝试从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. .h文件路径正确,我可以在智能感知中看到所有选项。

I would appriciate any idea which might help me resolve this issue. 我会提出任何可能帮助我解决此问题的想法。 Thanks 谢谢

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. 如果这是正确的,则尝试将所有其他项目构建为静态库 (.lib)(或共享库(.dll)),并将它们引用到您的主项目(窗体)中,这应该可以正常工作。

Right now you are trying to build an executable (.exe) from 12other .exe. 现在,您正在尝试从12other .exe构建可执行文件(.exe)。 It can't work. 不行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM