I just installed FLTK on Linux but I have a compile error

119 views
Skip to first unread message

ken williams

unread,
Oct 21, 2020, 9:07:47 AM10/21/20
to fltk.general
I just installed FLTK library on Linux with the standard commands: cmake .. / make / sudo make install

My understanding is that "make install" moved the library to /usr/local/include. And I found the folder there:

    [ken@Lnx include]$ pwd
    /usr/local/include
    [ken@Lnx include]$ ls
    FL
Now I want to run the test from "Programming Principle and Practice" with the code:

    #include <FL/Fl.h>
    #include <FL/Fl_Box.h>
    #include <FL/Fl_Window.h>
    int main()
    {
        Fl_Window window(200, 200, "Window title");
        Fl_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World!");
        window.show();
        return Fl::run();
    }

Initially I had include errors, but then I noticed the files in the FL folder have .H and not .h extensions.
They disappeared after changing that in the code .

But now I have this compile error:

    ken@Lnx fltk_test]$ g++ fltk_test.cpp
    /usr/bin/ld: /tmp/ccJWfQR3.o: warning: relocation against `_ZTV6Fl_Box' in read-only section `.text._ZN6Fl_BoxD2Ev[_ZN6Fl_BoxD5Ev]'
    /usr/bin/ld: /tmp/ccJWfQR3.o: in function `main':
    fltk_test.cpp:(.text+0x37): undefined reference to `Fl_Window::Fl_Window(int, int, char const*)'
    /usr/bin/ld: fltk_test.cpp:(.text+0x62): undefined reference to `Fl_Box::Fl_Box(int, int, int, int, char const*)'
    /usr/bin/ld: fltk_test.cpp:(.text+0x71): undefined reference to `Fl_Window::show()'
    /usr/bin/ld: fltk_test.cpp:(.text+0x76): undefined reference to `Fl::run()'
    /usr/bin/ld: fltk_test.cpp:(.text+0x97): undefined reference to `Fl_Window::~Fl_Window()'
    /usr/bin/ld: fltk_test.cpp:(.text+0xd0): undefined reference to `Fl_Window::~Fl_Window()'
    /usr/bin/ld: /tmp/ccJWfQR3.o: in function `Fl_Box::~Fl_Box()':
    fltk_test.cpp:(.text._ZN6Fl_BoxD2Ev[_ZN6Fl_BoxD5Ev]+0xf): undefined reference to `vtable for Fl_Box'
    /usr/bin/ld: fltk_test.cpp:(.text._ZN6Fl_BoxD2Ev[_ZN6Fl_BoxD5Ev]+0x22): undefined reference to `Fl_Widget::~Fl_Widget()'
    /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
    collect2: error: ld returned 1 exit status


I use Visual Studio Code Insiders and I configured "settings.json" to have these default settings that I wanted to make visible the library to future projects:

"C_Cpp.default.compilerPath": "/usr/bin/gcc",
"C_Cpp.default.includePath": ["/usr/local/include/"],

I configured "c_cpp_properties.json" with the same settings, that overwrites the default settings from "settings.json". 
But I get the same errors.

What else can I do? Thanks for your reply!



Greg Ercolano

unread,
Oct 21, 2020, 10:07:44 AM10/21/20
to fltkg...@googlegroups.com
On 2020-10-21 06:07, ken williams wrote:
> Now I want to run the test from "Programming Principle and Practice" with the code:
>
>     #include <FL/Fl.h>
>     #include <FL/Fl_Box.h>
>     #include <FL/Fl_Window.h>

Oh no, if the book has lowercase .h's, then I'm afraid it's a mistake in the book.
.H is correct for those.

You can get away with the wrong case on some platforms (windows + mac), but not on linux,
freebsd, etc.

FLTK uses ".H" for C++ includes, and ".h" for C include files.

> But now I have this compile error:
>
>     ken@Lnx fltk_test]$ g++ fltk_test.cpp

No, you can't just compile FLTK this way. There's many libraries that need to
be included on the command line.

Use instead:

fltk-config --compile fltk_test.cpp

..and you'll likely get better results. fltk-config has other command flags
to let you get the list of compiler flags, libraries, etc. if you're trying
to compile more complicated applications that have many modules using a Makefile.

But for a single .cpp file like you have, the above should work fine.

wea...@gmail.com

unread,
Oct 21, 2020, 10:09:43 AM10/21/20
to fltk.general
On Wednesday, October 21, 2020 at 3:07:47 PM UTC+2 ken.will...@gmail.com wrote:
I just installed FLTK library on Linux with the standard commands: cmake .. / make / sudo make install

My understanding is that "make install" moved the library to /usr/local/include. And I found the folder there:

    [ken@Lnx include]$ pwd
    /usr/local/include
    [ken@Lnx include]$ ls
    FL
Now I want to run the test from "Programming Principle and Practice" with the code:

    #include <FL/Fl.h>
    #include <FL/Fl_Box.h>
    #include <FL/Fl_Window.h>
    int main()
    {
        Fl_Window window(200, 200, "Window title");
        Fl_Box box(0, 0, 200, 200, "Hey, I mean, Hello, World!");
        window.show();
        return Fl::run();
    }

Initially I had include errors, but then I noticed the files in the FL folder have .H and not .h extensions.
They disappeared after changing that in the code .

But now I have this compile error:

    ken@Lnx fltk_test]$ g++ fltk_test.cpp

ken williams

unread,
Oct 21, 2020, 10:28:46 AM10/21/20
to fltkg...@googlegroups.com
Thanks Greg.. it works with fltk-config
Thanks wea...@gmail.com, I was so focused on installing it that I forgot about the documentation
Going back to reading it...

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/e4818faf-dad0-4704-a800-478c99873112n%40googlegroups.com.

Ian MacArthur

unread,
Oct 21, 2020, 11:09:36 AM10/21/20
to fltkg...@googlegroups.com
On 21 Oct 2020, at 15:28, ken williams wrote:
>
> Thanks Greg.. it works with fltk-config
> Thanks wea...@gmail.com, I was so focused on installing it that I forgot about the documentation
> Going back to reading it...


As an aside - what does Dr.S recommend to do for compiling stuff in his book?

You said you were following the book, so I wonder what mechanism it recommends...




ken williams

unread,
Oct 21, 2020, 11:16:54 AM10/21/20
to fltk.general
He is using Visual Studio but he doesn't have an express recommendation, as far as I know.
I started with VS on Windows.. but I switched VS Code and now to Linux to force myself to understand more of what's behind the scenes...

ken williams

unread,
Oct 22, 2020, 9:58:56 AM10/22/20
to fltk.general
It seems I can't compile it with g++ ...
I tried this:

    g++ hello.cpp -o hello -I/usr/local/include -L/usr/local/lib -lfltk -lXext -lX11 -lm

and I get this:

    /usr/bin/ld: /usr/local/lib/libfltk.a(Fl_X11_Window_Driver.cxx.o): undefined reference to symbol 'dlsym@@GLIBC_2.2.5'
    /usr/bin/ld: /usr/lib/libdl.so.2: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status

Could someone tell me what I should add or change?
hello.cpp is the one from the FLTK 1.4.0 documentation: https://fltk.gitlab.io/fltk/basics.html

Thank you!

Albrecht Schlosser

unread,
Oct 22, 2020, 10:57:59 AM10/22/20
to fltkg...@googlegroups.com
On 10/22/20 3:58 PM ken williams wrote:
> It seems I can't compile it with g++ ...
> I tried this:
>
>     g++ hello.cpp -o hello -I/usr/local/include -L/usr/local/lib -lfltk
> -lXext -lX11 -lm
>
> and I get this:
>
>     /usr/bin/ld: /usr/local/lib/libfltk.a(Fl_X11_Window_Driver.cxx.o):
> undefined reference to symbol 'dlsym@@GLIBC_2.2.5'
>     /usr/bin/ld: /usr/lib/libdl.so.2: error adding symbols: DSO missing
> from command line
>     collect2: error: ld returned 1 exit status
>
> Could someone tell me what I should add or change?

That particular error is (AFAICT) because you missed to include '-ldl'
in your command.

A more general approach would be to use either

$ fltk-config --compile hello.cxx

and learn from the output which options you need or to use fltk-config
to provide the necessary options for you, like this:

$ fltk-config --cxxflags
$ fltk-config --ld[static]flags

See docs and/or

$ fltk-config --help

for more info.

> Thank you!

Welcome.

ken williams

unread,
Oct 27, 2020, 6:01:12 AM10/27/20
to fltk.general
Thanks Albrecht,  I was able to compile Dr. S first example code with the command:

      g++ -w -Wall -std=c++14 Graph.cpp Window.cpp GUI.cpp Simple_window.cpp test.cpp `fltk-config --ldflags --use-images` -o test

But when I'm using "fltk-config" like below it doesn't work.

      fltk-config --ldflags --use-images --compile  Graph.cpp Window.cpp GUI.cpp Simple_window.cpp test.cpp -o test

Probably I should change something but I can't see it.
I could use only the g++ command, but it would be nice to understand how to use "fltk-config" also.
I attached the files, it someone wants to check it.

Thanks everyone for your help!

Graph_lib.tar.gz

Albrecht Schlosser

unread,
Oct 27, 2020, 8:09:53 AM10/27/20
to fltkg...@googlegroups.com
On 10/27/20 11:01 AM ken williams wrote:
> Thanks Albrecht,  I was able to compile Dr. S first example code with
> the command:
>
>       g++ -w -Wall -std=c++14 Graph.cpp Window.cpp GUI.cpp
> Simple_window.cpp test.cpp `fltk-config --ldflags --use-images` -o test

Great, thanks for the feedback.

> But when I'm using "fltk-config" like below it doesn't work.
>
>       fltk-config --ldflags --use-images --compile  Graph.cpp
> Window.cpp GUI.cpp Simple_window.cpp test.cpp -o test
>
> Probably I should change something but I can't see it.
> I could use only the g++ command, but it would be nice to understand how
> to use "fltk-config" also.

You can use fltk-config either to output some flags, for instance with

$ fltk-config --use-images --cxxflags

which outputs the compiler flags you need to compile a program with fltk
and fltk_images *or* you can use it to compile a *single* C++ source
file but you can't combine both in one command.

Options like '--use-images' are used to modify the output of the related
command, i.e. (in this case) add the fltk_images libs and corresponding
compiler flags.

Basically this means: if you want to compile more than one file you'd
better use a script or a Makefile or write a CMake project file
(CMakeLists.txt) and use that to build and compile your app.

Just in case you don't know: the backticks (`...`) in your command above
(`fltk-config --ldflags --use-images`) mean: run the given command in a
shell and insert the output of this command at this place in the command
line.
Reply all
Reply to author
Forward
0 new messages