简体   繁体   中英

can not link examples from programming principles and practice using c++

I'm trying to compile and link the following source code below. When I initiate the build sequence in Visual Studio 2012, I get the following errors (few more related to the Graph_lib). I don't understand why the linking is failing all the code is available. I have verified the symbol definition and declarations.

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 ==========

@dlf posted an MSDN link that suggested to add the .cpp files to the project. I followed the instructions and I'm now able to build and link successfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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