undefined reference error involving jpegs and images

687 views
Skip to first unread message

Fred Henderson

unread,
Jul 31, 2015, 7:26:13 PM7/31/15
to fltk.general
Greetings. This is a problem that is reasonably well documented on the net, but being a noob I don't really understand the solutions given, So I thought I would start anew. Here is one such instance of the problem
  https://www.gidforums.com/t-7803.html.

I am trying to do this example from Erco's cheat page http://seriss.com/people/erco/fltk/#Fl_JPG_Image. When I try to compile (link?) I get the following two error messages

||=== Build: Debug in jpegtest (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\cpp\jpegtest\main.cpp|8|undefined reference to `fl_register_images()'|
C:\cpp\jpegtest\main.cpp|11|undefined reference to `Fl_JPEG_Image::Fl_JPEG_Image(char const*)'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|

This is just a small example, but there are spillover effects to other projects I am working on. I am hoping for a solution that would fix this once and for all, rather than on a per project basis.

I am using Codeblocks with the latest and greatest from MinGW, on Windows XP

Greg Ercolano

unread,
Jul 31, 2015, 7:29:06 PM7/31/15
to fltkg...@googlegroups.com
On 07/31/15 16:22, Fred Henderson wrote:
> Greetings. This is a problem that is reasonably well documented on the net, but being a noob I don't really understand the solutions given, So I thought I would start anew. Here is one such instance of the problem
> https://www.gidforums.com/t-7803.html.
> C:\cpp\jpegtest\main.cpp|8|undefined reference to `fl_register_images()'|
> C:\cpp\jpegtest\main.cpp|11|undefined reference to `Fl_JPEG_Image::Fl_JPEG_Image(char const*)'|
> ||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|

Sounds like you're not linking in the fltk_images.lib library..

All the fltk image stuff is in a separate library from fltk.lib
since not everyone needs the image stuff in their apps.

So where you've added fltk.lib to the link line, tack fltk_images.lib too.



Greg Ercolano

unread,
Jul 31, 2015, 7:34:37 PM7/31/15
to fltkg...@googlegroups.com
On 07/31/15 16:29, Greg Ercolano wrote:
> On 07/31/15 16:22, Fred Henderson wrote:
>> C:\cpp\jpegtest\main.cpp|8|undefined reference to `fl_register_images()'|
>> C:\cpp\jpegtest\main.cpp|11|undefined reference to `Fl_JPEG_Image::Fl_JPEG_Image(char const*)'|
>
> So where you've added fltk.lib to the link line, tack fltk_images.lib too.

Oh, and if you're using fltk.dll (instead of fltk.lib), then use fltk_images.dll
Either way should solve that problem.

Note there are other .lib / .dll files in the fltk "lib" directory,
so if you get errors about functions related to those libs, include them
as well (jpeg, png, etc.. depends on how fltk was built)

Fred Henderson

unread,
Jul 31, 2015, 9:12:45 PM7/31/15
to fltk.general, erco_...@seriss.com

My IDE has a handy dandy FLTK wizard so I've never had to get my hands dirty. I am trying to upload a gif image of what I think is the appropriate dialog box to make the change you suggest. Does it look  like the right place.

Greg Ercolano

unread,
Jul 31, 2015, 9:17:25 PM7/31/15
to fltkg...@googlegroups.com
On 07/31/15 17:48, Fred Henderson wrote:
> <https://lh3.googleusercontent.com/-fN1KaI3UNh8/VbwXZtn9z8I/AAAAAAAAAB0/KfOQf0bl-I8/s1600/dialog.gif>
>
> My IDE has a handy dandy FLTK wizard so I've never had to get my hands dirty. I am trying to upload a gif image of what I think is the appropriate dialog box to make the change you suggest. Does it look like the right place.


Yes.. I imagine under "Other linker options:" try adding: fltk_images

If it doesn't like that, it may need instead -lfltk_images or fltk_images.dll
or fltk_images.lib.. try them in that order until it works.

If none of that works, put the fltk_images in there, then show us the
full log output from the build, esp. the linker command line and errors after that,
so we can see how the GUI translates what you type into the linker command line.

Fred Henderson

unread,
Jul 31, 2015, 9:47:55 PM7/31/15
to fltk.general, erco_...@seriss.com
this is my fltk lib directory

 Directory of C:\fltk\fltk-1.3.3\lib. does that look ok?

07/13/2015  10:57 PM    <DIR>          .
07/13/2015  10:57 PM    <DIR>          ..
07/13/2015  10:55 PM         2,040,488 libfltk.a
07/13/2015  10:56 PM            38,882 libfltk_forms.a
07/13/2015  10:56 PM           260,278 libfltk_gl.a
07/13/2015  10:57 PM            77,968 libfltk_images.a
07/13/2015  10:42 PM           399,992 libfltk_jpeg.a
07/13/2015  10:44 PM           263,316 libfltk_png.a
07/13/2015  10:42 PM           108,428 libfltk_z.a
06/24/2002  03:49 PM               579 README.lib

here is the build log with fltk_images in Other Linker Options

-------------- Build: Debug in jpegtest (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\fltk\fltk-1.3.3\lib -o bin\Debug\jpegtest.exe obj\Debug\main.o  fltk_images  -lfltk -lole32 -luuid -lcomctl32 -lwsock32 -lm -lgdi32 -luser32 -lkernel32
mingw32-g++.exe: error: fltk_images: No such file or directory
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 


here is the build log with libfltk_images.a in other linker options

-------------- Build: Debug in jpegtest (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\fltk\fltk-1.3.3\lib -o bin\Debug\jpegtest.exe obj\Debug\main.o  libfltk_images.a  -lfltk -lole32 -luuid -lcomctl32 -lwsock32 -lm -lgdi32 -luser32 -lkernel32
mingw32-g++.exe: error: libfltk_images.a: No such file or directory
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

Greg Ercolano

unread,
Jul 31, 2015, 10:33:45 PM7/31/15
to fltkg...@googlegroups.com
On 07/31/15 18:47, Fred Henderson wrote:
> here is the build log with libfltk_images.a in other linker options
> mingw32-g++.exe -LC:\fltk\fltk-1.3.3\lib -o bin\Debug\jpegtest.exe obj\Debug\main.o libfltk_images.a -lfltk -lole32 -luuid -lcomctl32 -lwsock32 -lm -lgdi32 -luser32 -lkernel32
> mingw32-g++.exe: error: libfltk_images.a: No such file or directory

Try: -lfltk_images

Fred Henderson

unread,
Jul 31, 2015, 10:44:18 PM7/31/15
to fltk.general, erco_...@seriss.com
with -lfltk_images in Other Linker Options I got a couple of new messages, as shown below



||=== Build: Debug in jpegtest (compiler: GNU GCC Compiler) ===|
C:\fltk\fltk-1.3.3\lib\libfltk_images.a(Fl_JPEG_Image.o):Fl_JPEG_Image.cxx:(.text$_ZN13Fl_JPEG_ImageC2EPKc+0x8a)||undefined reference to `jpeg_std_error'|
C:\fltk\fltk-1.3.3\lib\libfltk_images.a(Fl_JPEG_Image.o):Fl_JPEG_Image.cxx:(.text$_ZN13Fl_JPEG_ImageC2EPKc+0x128)||undefined reference to `jpeg_finish_decompress'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|

Ian MacArthur

unread,
Aug 1, 2015, 2:25:21 AM8/1/15
to fltkg...@googlegroups.com
On Sat Aug 01 2015 03:44:18, Fred Henderson wrote:
with -lfltk_images in Other Linker Options I got a couple of new messages, as shown below


OK, you are making progress; now, as Greg said earlier, you need to fill in the other libs as needed to fill the remaining dependencies...
Now it is saying you have not linked in the jpeg lib.
Next it will complain about PNG and libZ...

Or hit the lot...

-lfltk_images -lpng -lz -ljpeg -lfltk_gl -lfltk 



Fred Henderson

unread,
Aug 1, 2015, 1:13:33 PM8/1/15
to fltk.general
 Thanks, by adding a few more libs like this I was able to get rid of all my build errors.

The driving force behind this has been Stroustrup's beginner's book on C++. He spends five chapters on Graphics and GUI, using a self-designed interface to FLTK that supposedly simplifies things. He has a bunch of header and cpp files on his website you need to download and get running, not to mention getting FLTK properly installed in the first place. Let me tell you it has been a royal pain in the ass to deal with. I still have lot's of errors to get through.

Greg Ercolano

unread,
Aug 1, 2015, 2:10:06 PM8/1/15
to fltkg...@googlegroups.com
On 08/01/15 10:13, Fred Henderson wrote:
> Thanks, by adding a few more libs like this I was able to get rid of all my build errors.
>
> The driving force behind this has been Stroustrup's beginner's book on C++. He spends five chapters on Graphics and GUI, using a self-designed interface to FLTK that supposedly simplifies things. He has a bunch of header and cpp files on his website you need to download and get running, not to mention getting FLTK properly installed in the first place. Let me tell you it has been a royal pain in the ass to deal with. I still have lot's of errors to get through.

One of us on the dev team should get that book; perhaps we can address
common things people new to programming can run into initially.

You could probably help us to that end by letting us know here
things you learned/overcame during the process, as that info can
help others in the same situation.

Fred Henderson

unread,
Aug 1, 2015, 2:48:06 PM8/1/15
to fltk.general, erco_...@seriss.com
sounds like a good idea. There are a lot of people with the book, and a lot of beginners having problems. If I have anything to add I'll do  it in this thread.

over and out.

Fred Henderson

unread,
Aug 2, 2015, 1:17:55 PM8/2/15
to fltk.general, erco_...@seriss.com
Hi, this is a problem that is probably partly due to FLTK

I am trying to get the aforementioned FLTK interface up and running with a simple example, and at the moment I have just one error message.

The error message I have is

 undefined reference to `vtable for Graph_lib::Button'|

The build log is as follows...

-------------- Build: Debug in Graphics_PPP (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\fltk\fltk-1.3.3\lib -o bin\Debug\Graphics_PPP.exe obj\Debug\Graph.o obj\Debug\main.o obj\Debug\Window.o  -lfltk_images -lfltk_jpeg -lfltk_png -lfltk_z  -lfltk -lole32 -luuid -lcomctl32 -lwsock32 -lm -lgdi32 -luser32 -lkernel32
obj\Debug\main.o: In function `ZN9Graph_lib6ButtonC1ENS_5PointEiiRKSsPFvPvS4_E':
C:/cpp/Graphics_PPP/GUI.h:63: undefined reference to `vtable for Graph_lib::Button'
obj\Debug\main.o: In function `ZN9Graph_lib6ButtonD1Ev':
C:/cpp/Graphics_PPP/GUI.h:61: undefined reference to `vtable for Graph_lib::Button'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 2 second(s))

2 error(s), 0 warning(s) (0 minute(s), 2 second(s))

the relevant code snippet is...

61    struct Button : Widget {
62        Button(Point xy, int w, int h, const string& label, Callback cb)
63            : Widget(xy,w,h,label,cb)
64        {}
65
66        void attach(Window&);
67    };


I am sorry if I didn't include enough code, let me know if you want more. It was suggested to me on another site that  It looks like Button is failing to implement some pure virtual methods from Widget.

MacArthur, Ian (Selex ES, UK)

unread,
Aug 3, 2015, 5:36:41 AM8/3/15
to fltkg...@googlegroups.com
> > The driving force behind this has been Stroustrup's beginner's book
> on C++. He spends five chapters on Graphics and GUI, using a self-
> designed interface to FLTK that supposedly simplifies things. He has a
> bunch of header and cpp files on his website you need to download and
> get running, not to mention getting FLTK properly installed in the
> first place. Let me tell you it has been a royal pain in the ass to
> deal with. I still have lot's of errors to get through.
>
> One of us on the dev team should get that book; perhaps we can
> address
> common things people new to programming can run into initially.
>
> You could probably help us to that end by letting us know here
> things you learned/overcame during the process, as that info can
> help others in the same situation.


A while back (several years now) I did take a look - I don't have the book, but you can download the examples and stuff freely from the website.

I believe there has been a new edition of the book published since then, so I’d hope that the example code has been updated (I have not checked recently...)

My observations were:-

- The code pretty much just built out of the box for me, one WinXX/msys/mingw, and for OSX. The distributed samples expected to be built at the command line, and the WinXX build files were heavily MSVC oriented, but using the "unix" build scripts pretty much Just Worked.


- Dr.S.'s GUI code is somewhat... um... well, he does some things "under the covers" in his framework that are not really the fltk way, and on my (at the time very high-end multi-core Mac) that was actually causing problems because some GUI elements were spinning... I created patches, but never sent them; how do you tell Bjarne S. his code is wrong?
(I assume this will have been fixed by others in the meantime... Though I guess we could/should check...)


- (This next bit is going to sound hard on the OP, Fred, but I do not mean it to be) I lurked about to see what sort of comments the examples were getting, and there was *a lot* of traffic from folks trying the examples and struggling, often really quite badly.
After watching for a while it became apparent that the real issue was seldom the examples themselves (nor, indeed, fltk) but that the posters generally had a very poor grasp of what their toolchains did, how compilers/linkers work, how the libraries were linked in, how dependencies are resolved, and so forth. And many of these people were struggling to get IDE's running, where it seemed Dr.S. had not set up any IDE support (I guess he wants folks to use the tools and understand them...?)


So: yes we should pull a copy of the recent examples and try them. We probably ought to feed back any comments on his use of fltk to Dr.S. too, I suppose.

But whether we can (and even if we can, whether we should!) make it easier to build the examples? That is a much trickier question.





Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

MacArthur, Ian (Selex ES, UK)

unread,
Aug 3, 2015, 5:59:05 AM8/3/15
to fltkg...@googlegroups.com

> I believe there has been a new edition of the book published since
> then, so I’d hope that the example code has been updated (I have not
> checked recently...)

Oh, and I should have said it was (and apparently still is...) using fltk-1.1.9, so *very* ancient, and I'd be surprised if it really works at all on OSX these days...!

Greg Ercolano

unread,
Aug 3, 2015, 7:48:42 AM8/3/15
to fltkg...@googlegroups.com
On 08/02/15 10:17, Fred Henderson wrote:
> -------------- Build: Debug in Graphics_PPP (compiler: GNU GCC Compiler)---------------
> mingw32-g++.exe -LC:\fltk\fltk-1.3.3\lib -o bin\Debug\Graphics_PPP.exe obj\Debug\Graph.o obj\Debug\main.o obj\Debug\Window.o -lfltk_images -lfltk_jpeg -lfltk_png -lfltk_z -lfltk -lole32 -luuid -lcomctl32 -lwsock32 -lm -lgdi32 -luser32 -lkernel32
> obj\Debug\main.o: In function `ZN9Graph_lib6ButtonC1ENS_5PointEiiRKSsPFvPvS4_E':
> C:/cpp/Graphics_PPP/GUI.h:63: undefined reference to `vtable for Graph_lib::Button'
> obj\Debug\main.o: In function `ZN9Graph_lib6ButtonD1Ev':
> C:/cpp/Graphics_PPP/GUI.h:61: undefined reference to `vtable for Graph_lib::Button'
> collect2.exe: error: ld returned 1 exit status
> Process terminated with status 1 (0 minute(s), 2 second(s))
> 2 error(s), 0 warning(s) (0 minute(s), 2 second(s))
>
> the relevant code snippet is...
>
> 61 struct Button : Widget {
> 62 Button(Point xy, int w, int h, const string& label, Callback cb)
> 63 : Widget(xy,w,h,label,cb)
> 64 {}
> 65
> 66 void attach(Window&);
> 67 };

Hmm, the code above looks like fltk2 style (the use of "Widget", "Window", etc)
but your build is using fltk1.3.3 (which would be Fl_Widget, Fl_Window, etc)

In fltk1.x.x the fltk widget is Fl_Widget.
In fltk2 the fltk widget is Widget in the fltk2 namespace (IIRC)

Note: fltk2 never reached a release stage, and sometime around 2007 or so
the developers of that project simply.. stopped developing.

fltk 1.x is still the main development version, so be sure your
code is using fltk 1.x syntax.

Are the new editions of the book in question still referring to fltk2?
If so, that's a problem, as "fltk2" is no longer an active project.

MacArthur, Ian (Selex ES, UK)

unread,
Aug 3, 2015, 8:43:18 AM8/3/15
to fltkg...@googlegroups.com
> > the relevant code snippet is...
> >
> > 61 struct Button : Widget {
> > 62 Button(Point xy, int w, int h, const string& label,
> Callback cb)
> > 63 : Widget(xy,w,h,label,cb)
> > 64 {}
> > 65
> > 66 void attach(Window&);
> > 67 };
>
> Hmm, the code above looks like fltk2 style (the use of "Widget",
> "Window", etc)
> but your build is using fltk1.3.3 (which would be Fl_Widget,
> Fl_Window, etc)


Ah, no:- That's not really fltk code at all Greg, that's using Dr.S.'s GUI framework, which creates classes called "Window", "Widget", "Button", "Menu", etc. sort of derived from fltk(-1.1.9) classes.

(They are not really derived from fltk classes at all, for the most part, they are more like objects that point to fltk objects, as it were. For example the "Menu" class is actually a struct that points to an array of "Button" objects, not a wrapper for Fl_Menu, and so on.)

Anyway...

I do not know why, from the information given, the OP's code chokes. I speculate that the OP has forgotten to link in Dr.S.'s GUI framework in his build.
The errors reported would (I think) be consistent with not linking in GUI.cpp and Window.cpp into the build. (And possibly Graph.cpp and Simple_window.cpp too; I can't recall how the bits all fit together...)
Reply all
Reply to author
Forward
0 new messages