Saturday, 14 March 2020

Chapter 12 // Drill 1 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2017 and the graphics files found here:
https://github.com/l-paz91/principles-practice/tree/master/Graphics%20Files

Chapter 12 // Drill 1

Get an empty Simple_window with the size 600 by 400 and a label My Window compiled, linked, and run. Note that you have to link the FLTK library as described in Appendix D; #include Graph.h and Simple_window.h in your code; and include Graph.cpp and Window.cpp in your project.

Github: https://github.com/l-paz91/principles-practice/blob/master/Chapter%2012/Drill%201

This is quite possibly, the hardest exercise in the entire book if you have no experience with linking libraries. Fortunately, we had to use DirectX all throughout my uni course and I had to learn how to compile library binaries when starting SNES development so I wasn't completely stumped. The other annoying set back is the files you need are out of date and versions of FLTK numbered 1.1.x (as recommended in the book) no longer compiles on modern pc's. 

So, I've already written a few posts on how to get set up for this chapter so I'll link the appropriate ones here.

Setting up FLTK:

Fixed graphics files (this one took me a few hours):

EDIT 01/01/2021
I've now added a full project zip to github for this exercise:

Please make sure to use Simple_window2.h and not the original if you have reached this stage. I recommend downloading Bjarne's new files from here:

Errors you may encounter:
1>c:\users\lj\documents\fltk\fltk-1.3.5\fl\x.h(37): fatal error C1083: Cannot open include file: 'X11/Xlib.h': No such file or directory

I never encountered this on my first run and then I just kept using the same project. However when going over this again to create a new project I got this new error. Basically, if you double click on the error it takes you to x.H and it's complaining that it does't know what <x11/xlib.h> and friends are.

If you look a little further up on line 29, you'll notice that it hits these includes if we are not in WIN32 mode. If you are doing these exercises on Windows, it should know what WIN32 is, if it doesn't it means it cannot find the definition for the macro WIN32. This is defined in Windows.h which is included in the std_lib_facilities.h file. To fix these errors, simply put std_lib_facilities.h/windows.h before <Fl/fl...> includes (or "fltk.h"). 

I don't know why this isn't causing issues on my original project as the settings are all the same. Computers....

No comments:

Post a Comment