After installing FLTK 1.4.x on LinuxI'm working through Programming Principles and Practicebut now I'm stuck at drawing some Circles - which are drawn "fragmented".
On 4/21/21 9:38 AM, ken williams wrote:
Hi everyone!After installing FLTK 1.4.x on LinuxI'm working through Programming Principles and Practicebut now I'm stuck at drawing some Circles - which are drawn "fragmented".Please see attach.
On 4/21/21 11:15 AM, imm wrote:
I'm only looking at this on my phone, so may well be reading it wrong, but it looks to me like there's a lot of usage of curly-braces "{}" where I'd expect to use plain "()", so I wonder if that's contributing to the weirdness?
Indeed, good point -- though I figure the compiler wouldn't
build the app at all,
unless this is new C++ syntax I'm not familiar with (lambdas,
initializers..)
I figure Ian's referring to the {}s highlighted in red:
I'm only looking at this on my phone, so may well be reading it wrong, but it looks to me like there's a lot of usage of curly-braces "{}" where I'd expect to use plain "()", so I wonder if that's contributing to the weirdness?
Since many other folks use his books, we should probably at least be aware
of what to watch out for..
The first edition code can be found here. From this page.
On 4/22/21 3:16 AM, ken williams wrote:
Thanks everyone for your replies!
Here are my answers to some of the questions asked:
[..]
when I installed FLTK 1.4.x I used one of the archivesI'll try using the git version, I think I read somewhere it's the most up to date and I'll report back
On 4/22/21 4:40 AM, Greg Ercolano wrote:
On 4/22/21 3:16 AM, ken williams wrote:
when I installed FLTK 1.4.x I used one of the archivesI'll try using the git version, I think I read somewhere it's the most up to date and I'll report back
Yes Ken, 1.4.x is the latest and should work best.
Can you include (as an attachment) your .cpp / .h file(s), including your parens changes.
(In your original post the #include files weren't in there, so it's hard to build)
Just need your code, I have the book's code library already from Kevin's reply above.
But hmm, I get pages of build errors from the book's code..
wow.
This must be what Ian was talking about; I tried first with
g++ (4.8.5) on my SciLinux 7 machine,
then moved to my latest MacOS machine running Catalina with
clang (Apple clang version 12.0.0)
but just got different errors.
Not even sure where to start to address all this stuff to
build the above example:
I take it the book's code requires some very specific
compiler to build the book examples..
The readme.txt doesn't seem to require anything special for
unix builds.. hmm.
On 4/21/21 12:02 PM, lifeatt...@gmail.com wrote:
As far as I can tell, the .attach() syntax used appears to be a workaround to avoid relying on FLTK's begin() / end() mechanism for associating widgets. I don't know if this is a hold over from FLTK 1.x or an attempt to make the sample code clearer.
chapter.13.12.cpp: In function 'int main()':
chapter.13.12.cpp:23:9: error: 'struct Simple_window' has no member named 'attach'
23 | win.attach(c1);
| ^~~~~~
chapter.13.12.cpp:24:9: error: 'struct Simple_window' has no member named 'attach'
24 | win.attach(c2);
| ^~~~~~
chapter.13.12.cpp:25:9: error: 'struct Simple_window' has no member named 'attach'
25 | win.attach(c3);
| ^~~~~~
g++ -I"../GUI" -I"/c/fltk-1.4.x-git" -Wall -O3 -DNDEBUG -time -Wno-reorder chapter.13.12.cpp -o chapter.13.12
In file included from chapter.13.12.cpp:7:
../GUI/Simple_window.h:17:24: error: reference to 'Window' is ambiguous
17 | struct Simple_window : Window {
| ^~~~~~
In file included from ../GUI/GUI.h:10,
from ../GUI/Simple_window.h:10,
from chapter.13.12.cpp:7:
../GUI/Window.h:22:11: note: candidates are: 'class Graph_lib::Window'
22 | class Window : public Fl_Window {
| ^~~~~~
In file included from C:/fltk-1.4.x-git/FL/x.H:30,
from C:/fltk-1.4.x-git/FL/fl_draw.H:27,
from ../GUI/Graph.h:10,
from ../GUI/GUI.h:11,
from ../GUI/Simple_window.h:10,
from chapter.13.12.cpp:7:
C:/fltk-1.4.x-git/FL/win32.H:30:14: note: 'typedef struct HWND__* Window'
30 | typedef HWND Window;
| ^~~~~~
Also, you don't want to use "-Wall" !!! There are tons of warnings from the code. [attached]
On 4/22/21 5:30 AM, ken williams wrote:
But if you use my "Graph_lib" files and compile with:g++ -w -Wall -std=c++14 ../../Graph_lib/Graph.cpp ../../Graph_lib/Window.cpp ../../Graph_lib/GUI.cpp ../../Graph_lib/Simple_window.cpp 13.12_circle.cpp `fltk-config --ldflags --use-images` -o 13.12_circle.bindoes it work?
On 4/22/21 6:03 AM, Greg Ercolano wrote:
I think the problem there is the generic class "Window" being used by the book
might be colliding with the operating system's "Window" definition:
../GUI/Simple_window.h:17:24: error: reference to 'Window' is ambiguous
../GUI/Window.h:22:11: note: candidates are: 'class Graph_lib::Window'
22 | class Window : public Fl_Window {
30 | typedef HWND Window;
Found some more engery to tap back in.
Had to make a few more changes to the Makefile to get it
working with mingw64,
I'll try to make a patch or something at some point.
One problem involved changing the order of "-lfltk
-lfltk_images" to instead "-lfltk_images -lfltk".
The other involved making a special $(OS) entry for MinGW:
ifeq ($(OS),MINGW64_NT-6.3-9600)
LIBS := $(LIBS) -lfltk_jpeg -luser32 -lgdi32 -lshell32
-lole32 -luuid -lWs2_32 -lComCtl32
With that and a few other tweaks I can't remmeber now, was
able to get
chapter.13.12.exe built and running using:
cd code/Chapter13
make FLTK=/c/fltk-1.4.x-git clean chapter.13.12.exe
..resulting in:
Which looks good to me, so now I'll try the OP's code that includes the graphlib.
On 4/22/21 6:44 AM, ken williams wrote:
Greg, sorry for insisting, but it seems that you have the ambiguous reference issues that are solved here (see point 10):
typedef HWND Window;
I don't think FLTK can change it, as that name is an export
for fl_xid on the MSWindows platform:
platform.H:extern FL_EXPORT Window fl_xid_(const Fl_Window*
w);
The files from Dr. S Github/site have to be "fixed" like in that post (there's an attachment at the end).Or you could use my files, that are already fixed.
> g++ -O3 -s -Wall -Wextra ./Graph_lib/Graph.cpp ./Graph_lib/Window.cpp
./Graph_lib/GUI.cpp ./Graph_lib/Simple_window.cpp 13.12_circle2.cpp -o
13.12_circle2.exe -I/d/NxGen/Libraries/fltk-1.3.5
-I/d/NxGen/Libraries/fltk-1.3.5/png
-I/d/NxGen/Libraries/fltk-1.3.5/zlib
-I/d/NxGen/Libraries/fltk-1.3.5/jpeg -mwindows -DWIN32 -DUSE_OPENGL32
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mwindows -static-libgcc
-static-libstdc++ /d/NxGen/Libraries/fltk-1.3.5/lib/libfltk_images.a
/d/NxGen/Libraries/fltk-1.3.5/lib/libfltk_png.a
/d/NxGen/Libraries/fltk-1.3.5/lib/libfltk_z.a
/d/NxGen/Libraries/fltk-1.3.5/lib/libfltk_jpeg.a
/d/NxGen/Libraries/fltk-1.3.5/lib/libfltk.a -lole32 -luuid -lcomctl32Sorry for the naive question, but Makefiles are an alternative to this long command?
On 4/22/21 10:10 AM, ken williams wrote:
> g++ -O3 -s -Wall -Wextra ./Graph_lib/Graph.cpp ./Graph_lib/Window.cpp
./Graph_lib/GUI.cpp ./Graph_lib/Simple_window.cpp 13.12_circle2.cpp -o
13.12_circle2.exe -I/d/NxGen/Libraries/fltk-1.3.5
-I/d/NxGen/Libraries/fltk-1.3.5/png
-I/d/NxGen/Libraries/fltk-1.3.5/zlib
-I/d/NxGen/Libraries/fltk-1.3.5/jpeg -mwindows -DWIN32 -DUSE_OPENGL32
-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -mwindows -static-libgcc
-static-libstdc++ /d/NxGen/Libraries/fltk-1.3.5/lib/libfltk_images.a
/d/NxGen/Libraries/fltk-1.3.5/lib/libfltk_png.a
/d/NxGen/Libraries/fltk-1.3.5/lib/libfltk_z.a
/d/NxGen/Libraries/fltk-1.3.5/lib/libfltk_jpeg.a
/d/NxGen/Libraries/fltk-1.3.5/lib/libfltk.a -lole32 -luuid -lcomctl32
Sorry for the naive question, but Makefiles are an alternative to this long command?
..where the "c: a b" line defines the dependency of
'c' on a and b, and the command
below it (indented with a tab) is the command that
makes 'c' from 'a' and 'b'.
To run this Makefile you'd just run the command 'make', which
looks for the Makefile
in the current directory, and if it finds one, builds the
first target it finds in the file,
in this case the target is 'c'.
It then checks if the date stamps of either 'a' or 'b' are
newer than the date stamp on
'c', and if so, runs the 'cat' command to update 'c'.
If you run 'make' a second time, the date stamp of 'c' will be
newer than 'a' and 'b',
and won't do anything, saving the trouble of running the build
command a second time.
You can create really complex dependencies with this simple
syntax, and is really
all Makefiles are. You can set variables and do some simple
if/else stuff, but that's
mainly what Makefiles are.
The commands and filenames will just be longer, and in that
way may look more
intimidating, but it's a really simple concept.
A simple Makefile for a C++ program would be:
myprog: myprog.cpp myprog.h
g++ myprog.cpp -o myprog
d: e f
cat e f > d
g: c d
cat c d > g
..then if you just run 'make' it'll default to
building the first target only, 'c'.
If you run 'make d' then it'll only build target 'd'.
If you run 'make g', that's more interesting, because
building 'g' involves checking
if targets 'c' and 'd' are up to date, and if not, builds
those first, then builds 'g'.
And that is where a Makefile becomes useful in more complex
programs where
there's lots of .cpp and .h files that all need to be build
and combined into a single
executable, perhaps with libraries and Makefiles in other
directories.. that's where
it becomes really useful to manage very large
projects.
> If you could post a "real FLTK program" [without Dr S's stuff] that shows the issue we could test,
Circling (sorry! :) back to Albrecht's original request ...
I've attached my attempt at a "pure FLTK" version of the program in question. I've kept the "Point" struct, as it is sort of central to the original bug report, but have attempted to distill Stroustrup's SimpleWindow, Window, and Graph to the relevant, similar functionality.
Everybody please look it over and tell me if I missed anything!
simple-window.cxx:75:27: error: in C++98 'x' must be initialized by constructor, not by '{...}'It runs and draws the circles fine, though I can't close the program with the 'Exit' button
const Point x{250, 150};
^
simple-window.cxx:76:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
CircleWindow win{x, 600, 400, "Ch13 Circle"};
^
simple-window.cxx:76:48: error: in C++98 'win' must be initialized by constructor, not by '{...}'
CircleWindow win{x, 600, 400, "Ch13 Circle"};
It would be interesting to hear if the fltk samples from the test and examples folders build and run correctly on Ken’s system - I think from the prior posts he reported that he had built fltk from one of the snapshot tarballs, or possibly direct from git, so in either case the samples should all be present, and would by built by a typical build.
Especially the test/unittests program which has a "circles
and arcs" test
that is probably the same as the PPP code which appears to
call
fl_arc() center.x, center.y, radius2, radius2, 0, 360)
..to draw the circles. The radius values are simply 50, 100,
and 150
with different x,y centers.
(2) Line style. We saw artifacts with focus boxes etc. when line width was 0 (the default).
Maybe that's the issue here as well?
https://www.fltk.org/doc-1.4/group__fl__drawings.html#ga75ac53c05a97bbb01a22ff56a382f52d
@Ken: please try to add this before the fl_arc() call in the draw() method:
const int line_width = 1;
fl_line_style(FL_SOLID, line_width);
fl_arc(...);
On 4/22/21 4:42 PM, Albrecht Schlosser wrote:
GitHub Issue #156 "Incorrect rendering on Alpine Linux":
https://github.com/fltk/fltk/issues/156
Now I try to figure out how to do the Makefile if the files are in different folders.Is VPATH useful for this?
../somedir/some.lib:Beware that Makefiles are not like shell scripts in that multiple lines
cd ../somedir && make some.lib
../somedir/some.lib:..or this will work:
cd ../somedir && make some.lib
../somedir/some.lib:..but this will not work:
cd ../somedir && \
make some.lib
../somedir/some.lib:..because in that last one, "cd ../somedir" and "make some.lib" will be
cd ../somedir
make some.lib
clean:rm -rf *.o
> So, when you say you installed 1.3.5, and then installed 1.4; did you un-install 1.3.5 before you installed 1.4?yes, I uninstalled 1.3.5 before installing 1.4 - and 1.4 did not workedthen I uninstalled 1.4 and re-install 1.3.5 and 1.3.5 didn't work this timeso the only time it worked was at the first install (of 1.3.5)
> I don't know Manjaro, or how it sets things up, but when I see a path like "/run/media" I assume it is a path to a removable mediumit's a path to a NTFS partition on the same disk with my / and /home partitions for Linux.I was a Windows user until recently so the biggest partition is NTFS.I wanted to have FLTK there so I could use it from Windows too (and build in a different subfolder).If it's something wrong with that, I could increase the size /home to have a path like you said
################ template makefile ############### We don't know what compiler to use to build fltk on this machine - but fltk-config does...CXX = $(shell fltk-config --cxx)# Set the flags for compiler: fltk-config knows the basic settings, then we can add our own...CXXFLAGS = $(shell fltk-config --cxxflags) -w -Wall -std=c++14 -O3 -I/other/include/paths... -I/run/media/repos/fltk-1.4.x/ -I/run/media/repos/fltk-1.4.x/build/ -I/run/media/repos/fltk-1.4.x/build/lib/