无法将编程原理中的示例与使用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_PressC++Debugfirst_guiDebugfirst_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_PressC++Debugfirst_guifirst_guisource.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_PressC++Debugfirst_guifirst_guisource.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_PressC++Debugfirst_guiDebugfirst_gui.exe : fatal error LNK1120: 10 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
@dlf发布了一个MSDN链接,建议将.cpp文件添加到项目中。我按照指示进行了操作,现在我可以成功地构建和链接了。
相关文章:
- std::vector的包装器,使数组的结构看起来像结构的数组
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- 看起来is_nothrow_constructible_v()在MSVC中被破坏了,我错了吗
- 将大括号括起来的初始值设定项列表作为结构返回
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 将 SDL2 与 CMake 链接起来
- 调用重载的"<大括号括起来的初始值设定项列表>"对于对来说就足够了是模棱两可的
- 如何使用connect将qml按钮与同一类的cpp函数连接起来
- 尽管一切看起来都很好,但值不会交换
- 尝试将 c 字符串数组与分隔符连接起来
- 为什么我会收到此错误?无法将 {lb, ub} 从<大括号括起来的初始值设定项列表>转换为 float(**)(float*, int)
- 有没有办法生成一个包含平方的序列,这些平方加起来就是一个整数平方?
- 计算数组重复次数的组合的有效算法,加起来达到给定的总和
- 自制的上衣:看起来一样,但不完全相同
- 为什么这个复合语句作为用大括号和括号括起来的语句序列似乎不是有效的语句表达式
- 从双引号括起来的子字符串中删除特定字符
- 大括号括起来的初始值设定项列表中的短 c++ 类构造函数
- 嵌套的大括号括起来的初始值设定项列表
- 如何使它看起来像正在下的雪
- 如何在应用程序子项目中将静态库与gradle子项目链接起来