无法链接编程原理和使用c++的实践中的示例

问题描述 投票:0回答:2

我正在尝试编译并链接以下源代码。当我在 Visual Studio 2012 中启动构建序列时,出现以下错误(与 Graph_lib 相关的错误很少)。我不明白为什么链接失败,所有代码都可用。我已经验证了符号定义和声明。

Error   11  error LNK1120: 10 unresolved externals  C:\Microsoft_Press\C++\Debug\first_gui\Debug\first_gui.exe  first_gui
Error   4   error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Shape::draw_lines(void)const " (?draw_lines@Shape@Graph_lib@@MBEXXZ)   C:\Microsoft_Press\C++\Debug\first_gui\first_gui\source.obj first_gui
Error   1   error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Window::draw(void)" (?draw@Window@Graph_lib@@MAEXXZ)   C:\Microsoft_Press\C++\Debug\first_gui\first_gui\source.obj first_gui
Error   6   error LNK2001: unresolved external symbol "public: virtual void __thiscall 

#include "std_lib_facilities.h"
#include "Simple_window.h"
#include "Graph.h"

int main()
{
    using namespace Graph_lib;

    Point tl(100,100);

    Simple_window win(tl,600,400,"canvas");

    Polygon poly;

    poly.add(Point(300,200));
    poly.add(Point(350,100));
    poly.add(Point(400,200));

    poly.set_color(Color::red);

    win.attach(poly);
    win.wait_for_button();
}

1>------ Build started: Project: first_gui, Configuration: Debug Win32 ------
1>source.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Window::draw(void)" (?draw@Window@Graph_lib@@MAEXXZ)
1>source.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Shape::move(int,int)" (?move@Shape@Graph_lib@@UAEXHH@Z)
1>source.obj : error LNK2019: unresolved external symbol "protected: __thiscall Graph_lib::Shape::Shape(void)" (??0Shape@Graph_lib@@IAE@XZ) referenced in function "public: __thiscall Graph_lib::Open_polyline::Open_polyline(void)" (??0Open_polyline@Graph_lib@@QAE@XZ)
1>source.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall Graph_lib::Shape::draw_lines(void)const " (?draw_lines@Shape@Graph_lib@@MBEXXZ)
1>source.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Open_polyline::draw_lines(void)const " (?draw_lines@Open_polyline@Graph_lib@@UBEXXZ)
1>source.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Closed_polyline::draw_lines(void)const " (?draw_lines@Closed_polyline@Graph_lib@@UBEXXZ)
1>source.obj : error LNK2019: unresolved external symbol "public: void __thiscall Graph_lib::Polygon::add(struct Point)" (?add@Polygon@Graph_lib@@QAEXUPoint@@@Z) referenced in function _main
1>source.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Graph_lib::Polygon::draw_lines(void)const " (?draw_lines@Polygon@Graph_lib@@UBEXXZ)
1>source.obj : error LNK2019: unresolved external symbol "public: __thiscall Simple_window::Simple_window(struct Point,int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Simple_window@@QAE@UPoint@@HHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main
1>source.obj : error LNK2019: unresolved external symbol "public: bool __thiscall Simple_window::wait_for_button(void)" (?wait_for_button@Simple_window@@QAE_NXZ) referenced in function _main
1>C:\Microsoft_Press\C++\Debug\first_gui\Debug\first_gui.exe : fatal error LNK1120: 10 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
c++ visual-studio-2012
2个回答
1
投票

@dlf 发布了一个 MSDN 链接,建议将 .cpp 文件添加到项目中。我按照说明操作,现在可以成功构建和链接。


0
投票

需要添加到项目中的“那些”.cpp 文件是什么以及在哪里?

© www.soinside.com 2019 - 2024. All rights reserved.