簡體   English   中英

無法鏈接來自使用c ++的編程原理和實踐的示例

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

我正在嘗試編譯和鏈接下面的以下源代碼。 當我在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 ==========

@dlf發布了一個MSDN鏈接 ,該鏈接建議將.cpp文件添加到項目中。 我按照說明進行操作,現在可以成功建立和鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM