Hey all.
New to the forum and relatively new to C++. And definitely very green as far as non-Microsoft systems, but that's changing.
I've
been using Code::Blocks with Windows (and not Visual Studio because I'm
slowly weaning myself off of Microsoft altogether). After having
googled the web for about 4 days (tons of frustration, tons more
learning), here's how I got FLTK to work with Stroustrup's headers,
step-by-step in its entirety, sparing anyone else who's teaching
themselves this fascinating language from the same trouble.
Setting Up FLTK with the Code::Blocks IDE(1) Download Code::Blocks with the TDM-GCC compiler in version 4.8.1 (to run C++11), from here:
http://www.codeblocks.org/downloads/26
-- This version of the GCC compiler is enough to run everything (I
think), but if you'd like the updated version 5.1, you can get it from
Twilight Dragon Media's website at:
http://tdm-gcc.tdragon.net/download
-- I also think it's better to use TDM's compiler rather than the
standard GCC one because it's got some extra tweaks for Windows, and
besides that's the compiler that comes standard with the Code::Blocks
IDE (but, I haven't tried anything else).
-- I set
TDM-GCC-5.1 directly on C:\TDM-GCC-32, then changed CB's "Settings ->
Compiler -> Toolchain executables -> Compiler's instalation
directory" to "C:\TDM-GCC-32" to get C::B to use it.
(2) Download the Minimalistic GNU for Windows (MinGW) software here:
http://sourceforge.net/projects/mingw/files/latest/download
-- For those who don't know (like me until recently), MinGW was created
specifically to use GNU software (normally for Unix-like operating
systems) on the Windows command line
-- Set it up at c:\mingw
-- Make sure you place "C:\mingw" in the Path; you may need to restart after it's in there for it to work.
-- Also, make sure you download MSYS, which comes with the mingw
package as an optional download. Msys ("Minimal system") is a
Linux-like but extremely minimalistic command line, just enough to
configure things like FLTK.
-- Once you've got msys set up, open this file in a text editor (e.g., Notepad++): C:\MinGW\msys\1.0\etc\fstab
-- "fstab" has no extension, but it's a text file.
-- In this text file, write: "C:\MinGW /mingw" (this just lets
Msys know where MinGW is when it's gotta use it; more here:
http://www.mingw.org/wiki/mingw and here:
http://www.mingw.org/wiki/MSYS)
(3) Download FLTK 1.3.3 from http://www.fltk.org/software.php -- Get the tarball version. For the clueless: it can be opened in Win by 7-Zip (here:
http://www.7-zip.org/)
just like any standard Windows zip file (this was a real epiphany for
me. Tarballs are normally for Unix-like systems, and I thought it was
hopeless until I tried it out by chance).
-- Extract the fltk-1.3.3 directory to C:\fltk-1.3.3
-- Build fltk with Msys:
-- Go to C:\MinGW\msys\1.0, and run "Msys" (a batch file)
-- Then, once you're in the Msys shell/command line, type:
cd /c/fltk-1.3.3
./configure
make
-- If you're interested, see
http://www.fltk.org/documentation.php and
https://www.gnu.org/software/make/manual/
for what all this means; in brief, you're using "make" to build (i.e.,
compile and link and possibly some other stuff to get it to work) FLTK.
(4) Finally, open Code::Blocks and select File -> New -> Project -> FLTK project -- C::B will ask you to "Please select FLTK’s location:". Enter "c:\fltk-1.3.3"
-- Then there's one more C::B screen asking if you want to use Fluid (a
program that comes with FLTK), just go for "main()" instead
(5) Test it out
with either with the mini-program given in there (which I don't
understand yet), or via Stroustrup's "D.5 Testing if it all worked" (p.
1206) program. It should work!
Getting Bjarne's Headers to WorkThough
you now should have a working copy of FLTK, you can't use it with the
simplified statements Stroustrup gives. I think he's eliminated all the
extras to help one see, without distraction, exactly what's happening
at the core of any graphics engine. But to do that, he used quite a few
modifications to fltk that are, I take it anyway,
outdated/implementation-specific. Hence the reason so many people
are having (and publishing) so much trouble with this. Besides the fact
that there are purposeful (but minor) errors in there so the drill
really sticks.
I tried two versions of the header files from this group, at
https://groups.google.com/forum/#!topic/ppp-public/gTS_UIMEseM and
https://groups.google.com/forum/#!topic/ppp-public/BtlzdWGuQpQ, but neither of them worked! (might be because I'm not using Microsoft's Visual Studio compiler).
So here's the version that finally worked for me using the GCC. Note that this was taken from
https://bewuethr.github.io/installing-fltk-133-under-visual-studio/
--- but once you get FLTK to work on whatever (IDE and/or) compiler
you're using, you then have this priceless little gem further down the
webpage: "Getting FLTK with headers from Stroustrup's book to run"
I
did everything there, plus added a couple of other minor changes to get
the headers to work. For example, I commented out lines 336--349 in
"Graph.cpp" because they were stubbornly causing a bunch of errors and
that switch() block is a little too advanced for me (it uses
still-so-scary pointers). The result: I can't add any pictures to my
window, but that's ok for now until I understand what it is I've
actually done here.
Also, I added "Graph_lib" to "Polygon poly;"
for the fully qualified "Graph_lib::Polygon poly;" --- otherwise it's
ambiguous, Polygon could refer to the original "Polygon" defined in
<wingdi.h> (Windows Graphics Device Interface I'm guessing), or it
could refer to Stroustrup's simplified Polygon.
If
you're worried about really understanding it, I think Stroustrup has
the (excellent imo) policy that you should learn how to
do, first. Then, once you have the hang of it, learn (very probably in subsequent chapters) exactly
why it is as it is.