如何修复书'Programmin principles and practice Using C++'中的 FLTK 头文件?
How to fix the FLTK header files from 'Programmin principles and practice Using C++' book?
我遵循"使用C 的编程原理和练习",并进入了GUI引入的第12章。但是,我无法从书籍中获取自定义标头文件来工作。在尝试了专门为本书安装FLTK的多个指南之后,我在本指南中获得了最远的方法:https://bumpyroadtocode.com/2017/08/05/how-to-to-now-to-ind-og-install-and-use-fltk-1-3-3-4-In-Visual-Studio-2017-Complete指定/#注释
我对标头文件进行了与消除大多数错误但并非全部的更改。在评论了Simple_window.h和simple_window.cpp中的一些重复声明后,我只剩下7个错误。但是,由于我是C 的新手(否则我可能不会读这本书(,所以我无法摆脱最后几个错误:(
这些是错误:
Severity Code Description Project File Line Suppression State
Error LNK2005 "void __cdecl seed_randint(int)" (?seed_randint@@YAXH@Z) already defined in Graph.obj Programming Principles and Practice Using C++ C:UsersCM Storm i7sourcereposProgramming Principles and Practice Using C++Programming Principles and Practice Using C++Window.obj 1
Error LNK2005 "class std::mersenne_twister_engine<unsigned int,32,624,397,31,2567483615,11,4294967295,7,2636928640,15,4022730752,18,1812433253> & __cdecl get_rand(void)" (?get_rand@@YAAAV?$mersenne_twister_engine@I$0CA@$0CHA@$0BIN@$0BP@$0JJAILANP@$0L@$0PPPPPPPP@$06$0JNCMFGIA@$0P@$0OPMGAAAA@$0BC@$0GMAHIJGF@@std@@XZ) already defined in Graph.obj Programming Principles and Practice Using C++ C:UsersCM Storm i7sourcereposProgramming Principles and Practice Using C++Programming Principles and Practice Using C++GUI.obj 1
Error LNK2005 "class std::mersenne_twister_engine<unsigned int,32,624,397,31,2567483615,11,4294967295,7,2636928640,15,4022730752,18,1812433253> & __cdecl get_rand(void)" (?get_rand@@YAAAV?$mersenne_twister_engine@I$0CA@$0CHA@$0BIN@$0BP@$0JJAILANP@$0L@$0PPPPPPPP@$06$0JNCMFGIA@$0P@$0OPMGAAAA@$0BC@$0GMAHIJGF@@std@@XZ) already defined in Graph.obj Programming Principles and Practice Using C++ C:UsersCM Storm i7sourcereposProgramming Principles and Practice Using C++Programming Principles and Practice Using C++Simple_window.obj 1
Error LNK2005 "class std::mersenne_twister_engine<unsigned int,32,624,397,31,2567483615,11,4294967295,7,2636928640,15,4022730752,18,1812433253> & __cdecl get_rand(void)" (?get_rand@@YAAAV?$mersenne_twister_engine@I$0CA@$0CHA@$0BIN@$0BP@$0JJAILANP@$0L@$0PPPPPPPP@$06$0JNCMFGIA@$0P@$0OPMGAAAA@$0BC@$0GMAHIJGF@@std@@XZ) already defined in Graph.obj Programming Principles and Practice Using C++ C:UsersCM Storm i7sourcereposProgramming Principles and Practice Using C++Programming Principles and Practice Using C++Window.obj 1
Error LNK2005 "void __cdecl seed_randint(int)" (?seed_randint@@YAXH@Z) already defined in Graph.obj Programming Principles and Practice Using C++ C:UsersCM Storm i7sourcereposProgramming Principles and Practice Using C++Programming Principles and Practice Using C++GUI.obj 1
Error LNK2005 "void __cdecl seed_randint(int)" (?seed_randint@@YAXH@Z) already defined in Graph.obj Programming Principles and Practice Using C++ C:UsersCM Storm i7sourcereposProgramming Principles and Practice Using C++Programming Principles and Practice Using C++Simple_window.obj 1
Error LNK1169 one or more multiply defined symbols found Programming Principles and Practice Using C++ C:UsersCM Storm i7sourcereposProgramming Principles and Practice Using C++DebugProgramming Principles and Practice Using C++.exe 1
这是simple_window.h:
#include "GUI.h" // for Simple_window only (doesn't really belong in Window.h)
using namespace Graph_lib;
// Simple_window is basic scaffolding for ultra-simple interaction with graphics
// it provides one window with one "next" button for ultra-simple animation
struct Simple_window : Graph_lib::Window {
Simple_window(Point xy, int w, int h, const string& title);
/*
: Window(xy, w, h, title),
button_pushed(false),
next_button(Point(x_max() - 70, 0), 70, 20, "Next", cb_next) {
attach(next_button);
}
*/
bool wait_for_button();
// modified event loop
// handle all events (as per default), but quit when button_pushed becomes true
// this allows graphics without control inversion
/*
{
while (!button_pushed) Fl::wait();
button_pushed = false;
Fl::redraw();
}
*/
Button next_button;
private:
bool button_pushed;
static void cb_next(Address, Address addr); // callback for next_button
// { reference_to<Simple_window>(addr).next(); }
/*
{
static_cast<Simple_window*>(addr)->next();
}
*/
void next(); //{ button_pushed = true; }
};
最后,这是simple_window.cpp:
//
// This is a GUI support code to the chapters 12-16 of the book
// "Programming -- Principles and Practice Using C++" by Bjarne Stroustrup
//
#include "Simple_window.h"
//------------------------------------------------------------------------------
Simple_window::Simple_window(Point xy, int w, int h, const string& title) :
Window(xy, w, h, title),
next_button(Point(x_max() - 70, 0), 70, 20, "Next", cb_next),
button_pushed(false)
{
attach(next_button);
}
//------------------------------------------------------------------------------
bool Simple_window::wait_for_button()
// modified event loop:
// handle all events (as per default), quit when button_pushed becomes true
// this allows graphics without control inversion
{
show();
button_pushed = false;
#if 1
// Simpler handler
while (!button_pushed) Fl::wait();
Fl::redraw();
#else
// To handle the case where the user presses the X button in the window frame
// to kill the application, change the condition to 0 to enable this branch.
Fl::run();
#endif
return button_pushed;
}
//------------------------------------------------------------------------------
void Simple_window::cb_next(Address, Address pw)
// call Simple_window::next() for the window located at pw
{
reference_to<Simple_window>(pw).next();
}
//------------------------------------------------------------------------------
void Simple_window::next()
{
button_pushed = true;
hide();
}
//------------------------------------------------------------------------------
有两个选择可以解决此问题,尽管不知道,这是更好的:
1(评论" std_lib_facilities.h"中的随机数生成器218-228
或
2(项目 - 正当 - 链接器 - 所有选项 - 附加选项=>编辑并添加/force:多重
都对我有用,也希望你。
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- .cpp和.h文件中的模板专用化声明
- 反向给定链表中的K节点
- 正在查找文档以获得PS4平台的C++中的设备信息
- enum是C++中的宏变量还是整数变量
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 将字符串存储在c++中的稳定内存中
- 文本文件中的单词链表
- 递归函数计算序列中的平方和(并输出过程)
- 如何从C++中的依赖类型中获得它所依赖的类型
- C++中的"inline"关键字
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 用C++中的一个变量定义一个常量
- vector.resize()中的分配错误
- 使用指针从C++中的数组中获取最大值
- arr[-1]在c++中的奇怪行为
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 将值指定给向量(2D)的向量中的某个位置
- 内置函数可查看CPP中的成员变量