Making It Work: Code::Blocks IDE (GCC Compiler), FLTK, and Stroustrup's Headers

2,249 views
Skip to first unread message

divagantor

unread,
Oct 15, 2015, 6:22:35 PM10/15/15
to PPP-public
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 Work


Though 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.

Mark Wilmoth

unread,
Oct 23, 2015, 7:38:04 AM10/23/15
to PPP-public
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).
 

It could be. I am using MSYS2 https://sourceforge.net/projects/msys2/ and its GNU Make and MinGW builds. I used the files from https://groups.google.com/forum/#!topic/ppp-public/BtlzdWGuQpQ and it works. I had to change line 313 in Graph.cpp from "return ff;" to "return ff.good();".

 
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.
 

It should work if you add -lfltk_images -lfltk_png -lfltk_jpeg to your Linker Settings.  Make sure you pug -lfltk_images before -lfltk in Build Options->Linker Setting->Other Linker Settings. 


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.


I had to do that too! :)

Here is my build log using MinGW: (I used NetBeans IDE 8.1)

cd 'C:\Users\MackSix\Documents\NetBeansProjects\PPP2ED'
C:\Developer\msys64\usr\bin\make.exe -f Makefile CONF=Debug
"/C/Developer/msys64/usr/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/c/Users/MackSix/Documents/NetBeansProjects/PPP2ED'
"/C/Developer/msys64/usr/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/ppp2ed.exe
make[2]: Entering directory '/c/Users/MackSix/Documents/NetBeansProjects/PPP2ED'
mkdir -p build/Debug/MinGW-Windows/_ext/7e504010
rm -f "build/Debug/MinGW-Windows/_ext/7e504010/GUI.o.d"
g++ -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64   -c -g -I../../../../../Developer/lib/c++/FLTK/include -I../../../../../Developer/lib/c++/PPP2_Support_Code -I../../../../../Developer/lib/c++/FLTK/include/FL/images -std=c++11 -MMD -MP -MF "build/Debug/MinGW-Windows/_ext/7e504010/GUI.o.d" -o build/Debug/MinGW-Windows/_ext/7e504010/GUI.o ../../../../../Developer/lib/c++/PPP2_Support_Code/GUI.cpp
mkdir -p build/Debug/MinGW-Windows/_ext/7e504010
rm -f "build/Debug/MinGW-Windows/_ext/7e504010/Graph.o.d"
g++ -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64   -c -g -I../../../../../Developer/lib/c++/FLTK/include -I../../../../../Developer/lib/c++/PPP2_Support_Code -I../../../../../Developer/lib/c++/FLTK/include/FL/images -std=c++11 -MMD -MP -MF "build/Debug/MinGW-Windows/_ext/7e504010/Graph.o.d" -o build/Debug/MinGW-Windows/_ext/7e504010/Graph.o ../../../../../Developer/lib/c++/PPP2_Support_Code/Graph.cpp
mkdir -p build/Debug/MinGW-Windows/_ext/7e504010
rm -f "build/Debug/MinGW-Windows/_ext/7e504010/Simple_window.o.d"
g++ -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64   -c -g -I../../../../../Developer/lib/c++/FLTK/include -I../../../../../Developer/lib/c++/PPP2_Support_Code -I../../../../../Developer/lib/c++/FLTK/include/FL/images -std=c++11 -MMD -MP -MF "build/Debug/MinGW-Windows/_ext/7e504010/Simple_window.o.d" -o build/Debug/MinGW-Windows/_ext/7e504010/Simple_window.o ../../../../../Developer/lib/c++/PPP2_Support_Code/Simple_window.cpp
mkdir -p build/Debug/MinGW-Windows/_ext/7e504010
rm -f "build/Debug/MinGW-Windows/_ext/7e504010/Window.o.d"
g++ -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64   -c -g -I../../../../../Developer/lib/c++/FLTK/include -I../../../../../Developer/lib/c++/PPP2_Support_Code -I../../../../../Developer/lib/c++/FLTK/include/FL/images -std=c++11 -MMD -MP -MF "build/Debug/MinGW-Windows/_ext/7e504010/Window.o.d" -o build/Debug/MinGW-Windows/_ext/7e504010/Window.o ../../../../../Developer/lib/c++/PPP2_Support_Code/Window.cpp
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/main.o.d"
g++ -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64   -c -g -I../../../../../Developer/lib/c++/FLTK/include -I../../../../../Developer/lib/c++/PPP2_Support_Code -I../../../../../Developer/lib/c++/FLTK/include/FL/images -std=c++11 -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW-Windows
g++ -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64    -o dist/Debug/MinGW-Windows/ppp2ed build/Debug/MinGW-Windows/_ext/7e504010/GUI.o build/Debug/MinGW-Windows/_ext/7e504010/Graph.o build/Debug/MinGW-Windows/_ext/7e504010/Simple_window.o build/Debug/MinGW-Windows/_ext/7e504010/Window.o build/Debug/MinGW-Windows/main.o -L../../../../../Developer/lib/c++/FLTK/lib -mwindows -lfltk_images -lfltk -lfltk_png -lfltk_jpeg -lole32 -luuid -lcomctl32
make[2]: Leaving directory '/c/Users/MackSix/Documents/NetBeansProjects/PPP2ED'
make[1]: Leaving directory '/c/Users/MackSix/Documents/NetBeansProjects/PPP2ED'

BUILD SUCCESSFUL (total time: 24s)
Message has been deleted
Message has been deleted

C++Complexity

unread,
Apr 11, 2016, 12:57:04 PM4/11/16
to PPP-public
Hi, I tried your steps and it doesn't work. The msys compiler crashes while trying to compile some of the source code modules.

divagantor

unread,
Apr 12, 2016, 12:27:01 PM4/12/16
to PPP-public
Hey,

Not sure what's wrong (and I'm still a beginner with linux commands as well, so I'm not sure if I could help you even if you gave me more info).  But you can always try these sites:

See what they say about installing FLTK (from 2006 but still relevant):
http://www.fltk.org/articles.php?L598

http://www.fltk.org/cmp.php
"The FLTK build system uses GNU autoconf to tailor the library to the local operating system. Project files for major IDEs are also provided for Microsoft Windows®. To improve portability, makefiles must not make use of the unique features offered by GNU make. See the Makefile Standards section for a description of the allowed make features and makefile guidelines."

"Additional GNU build programs such as GNU automake and GNU libtool must not be used. GNU automake produces non-portable makefiles which depend on GNU-specific extensions, and GNU libtool is not portable or reliable enough for FLTK."

Then there's the make manual and some other forum:
https://www.gnu.org/software/make/manual/
https://www.gidforums.com/t-24753.html

Hope this helps.

By the way a very belated thanks to Mark Wilmoth.  I took your suggestion and therefore got the pictures working shortly after!

Mark McNaughton

unread,
Mar 19, 2018, 3:49:15 PM3/19/18
to PPP-public
I counldn't get it working. Followed all the steps but when starting a new fltk project in C::B I get an error saying it couldn't find the include folder.
Reply all
Reply to author
Forward
0 new messages