Historically I've built from source and maintained third party packages in each project (that's overkill for you) which allowed me to manage dependencies separately for each project and never install anything.
Didn't actually do the exercise just randomly picked this question to answer while reviewing past couple of weeks of mostly unanswered questions.
For this question my steps were:
downloaded https://github.com/BjarneStroustrup/Programming-_Principles_and_Practice_Using_Cpp
cd path/to/Programming-_Principles_and_Practice_Using_Cpp
brew install fltk (doesn't matter where you run this)
created your MY_CPP_FILE.cpp
created build.sh with your g++ -w -Wall -std=c++11 Graph.cpp Window.cpp GUI.cpp MY_CPP_FILE.cpp `fltk-config --ldflags --use-images` -o MY_EXECUTABLE
chmod u+x build.sh
./build.sh
fixed the compilation errors then thought someone else must already have done this so checked pull requests and issues
reviewed my fixes against https://github.com/BjarneStroustrup/Programming-_Principles_and_Practice_Using_Cpp/pull/13/commits/ccb56864ac2a932bb85ef27699226b172ad796f9
chmod u+x MY_EXECUTABLE
./MY_EXECUTABLE (make sure you click the button and not the close box)
screenshot
You'll probably need to clean out what you have manually built from source and installed. Homebrew will manage fltk dependences for you.
brew deps fltk
jpeg-turbo
libpng
fltk-config provides information about the installed library:
fltk-config
Usage: fltk-config [OPTIONS]
Options:
[--version]
[--api-version]
Options telling what we are doing:
[--use-gl] use GL
[--use-images] use extra image formats (PNG, JPEG)
[--use-glut] use glut compatibility layer
[--use-forms] use forms compatibility layer
[--use-cairo] use cairo graphics lib
Options telling what information we request:
[--cc] return C compiler used to compile FLTK
[--cxx] return C++ compiler used to compile FLTK
[--optim] return compiler optimization used to compile FLTK
[--cflags] return flags to compile C using FLTK
[--cxxflags] return flags to compile C++ using FLTK
[--ldflags] return flags to link against FLTK
[--ldstaticflags] return flags to link against static FLTK library
even if there are DSOs installed
[--libs] return FLTK libraries full path for dependencies
[--prefix] return FLTK install time --prefix directory
[--includedir] return FLTK install time include directory
Options to compile and link an application:
[-g] compile the program with debugging information
[-Dname[=value]] compile the program with the given define
[--compile program.cxx]
[--post program] prepare the program for desktop use
fltk-config --ldflags --use-images
-L/usr/local/Cellar/fltk/1.3.8_1/lib -lfltk_images -lpng -lz -ljpeg -lfltk -lpthread -framework Cocoa
Note that Homebrew installs into /usr/local on Intel and /opt/homebrew on Apple Silicon.