6

I have been trying to install this FLTK library:

sudo apt-get install libfltk1.3-dev
sudo apt-get install libx11-dev

I created simple main.cpp:

#include <fltk/Window.h>
#include <fltk/Widget.h>
#include <fltk/run.h>
using namespace fltk;

int main(int argc, char **argv) {
  Window *window = new Window(300, 180);
  window->begin();
  Widget *box = new Widget(20, 40, 260, 100, "Hello, World!");
  box->box(UP_BOX);
  box->labelfont(HELVETICA_BOLD_ITALIC);
  box->labelsize(36);
  box->labeltype(SHADOW_LABEL);
  window->end();
  window->show(argc, argv);
  return run();
}

and tried to compile using:

g++ -o win main.cpp

After this failure I followed the original instruction what come with FLTK which looked like this

Open a shell and install some software:

sudo apt-get install g++   
sudo apt-get install gdb   
sudo apt-get install subversion  
sudo apt-get install autoconf   
sudo apt-get install libx11-dev   
sudo apt-get install libglu1-mesa-dev    

These two are optional, but highly recommended:

sudo apt-get install libasound2-dev   
sudo apt-get install libxft-dev

If you are planning to use the Code::Blocks IDE, also install this

sudo apt-get install codeblocks

I like to use subversion to install the latest FLTK-1.3.release:

svn co http://seriss.com/public/fltk/fltk/branches/branch-1.3/ fltk-1.3

To update to the latest version, just go into the fltk-1.3 directory and type

svn update

FIXME: no FL_SYMBOL font (--symbol-), font 15 (Zapf-Dingbats)

When I tried to run this line

svn co http://seriss.com/public/fltk/fltk/branches/branch-1.3/ fltk-1.3 

I was asked for some password and I just entered my Ubuntu username password, which of course was not correct. Probably shouldn't have done it anyway

Authentication realm: <http://seriss.com:80> Subversion repository

So this is my story and here I am asking for some advice!

EDIT : Here is the older code that also didn't work

#include <FL/Fl.h>
#include <FL/Fl_Box.h>
#include <Fl/Fl_Windows.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()
}

This was the error :

main.cpp:1:19: fatal error: FL/Fl.h: No such file or directory
 #include <FL/Fl.h>
                   ^
compilation terminated.
2
  • Did you try the older code after installing libfltk1.3-dev?
    – muru
    May 25, 2015 at 5:43
  • yes I just now tried it, coz i woke up. I installed libfltk1.3-dev yesterday
    – etrusks
    May 25, 2015 at 5:45

2 Answers 2

9

For anyone looking for a way to make working this code on Stroustrup's book "Programming: Principles and Practice", appendix D, there is a little mistake in the header:

#include <FL/Fl.h>
#include <FL/Fl_Box.h>
#include <FL/Fl_Windows.h>

but in Ubuntu (or better said: in Linux) you should be very careful with your cases, so you should have

#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Windows.H>

To check what is the EXACT name of a header, just look on /usr/include/FL/

To have an executable from this file (in this post, main.cpp), one just have to use

$ fltk-config --compile main.cpp

which generates the executable main

$ ./main

and a simple window will show.

By the way, on Kubuntu 14.04 I installed FLTK with

$ sudo apt install fltk1.3-dev

which is version 1.3.2 (new enough for my needs).

2
  • So. Many. Mistakes in the FLTK stuff in that book. It would be great if they really put forth a serious effort to fix this in the third edition and make the GUI stuff work in Linux without having to spend a week in hell.
    – neuronet
    Jun 10, 2018 at 16:40
  • I am a bit late to the party, but I just had the same issue when trying to use FLTK together with Code Block. It was building fine when using the command line and the "fltk-config --compile" command. I had a look at the build message in Code Block and installed all the dev versions of the missing libraries (xcursor, fontconfig, ...). Now, it is working like a charme.
    – Strohmi
    Apr 4, 2020 at 20:10
3

Regarding the gcc build failure: It looks like you're using an FLTK 2.0 example and trying to compile it with FLTK 1.3.

If you're going to use 1.3, there is a PDF with examples that gets installed to /usr/share/doc/fltk1.3-doc/fltk.pdf.gz (from package fltk1.3-doc).

Regarding the svn problem: you're trying to log into someone's svn repo, and they require a username and password. You should probably change the password on your local system now because you just tried to use it to log into some other system on the internet.


Edit: Now that you've updated your code the problem has moved slightly... The problems at this point are the include path, the linker flags, and the typos.

When you see a failure on an include line it's because the compiler doesn't know where to look for the specified file (or it doesn't exist on your system). So you have to add the include path to your compile instruction. Once you move past that, you'll still need to specify appropriate linker flags so that the library that contains the objects for the included files are available to the linker.

You have some typos in your 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();
}

And you need a series of confusing libraries and includes, assuming it were named something like snippet.cpp compile it like this:

g++ `fltk-config --cxxflags` snippet.cpp `fltk-config --libs` -lX11 -ldl -lXext -lXinerama -lXft -lfontconfig -o snippet

Regarding the include path: The fltk-config --cxxflags command is producing a set of flags to pass to your gcc. Run it by itself if you want to see what those flags are.

Regarding the linker path: Again, the fltk-config (with --libs) command is providing the flags for the linker.

The string of other linker flags were almost a complete guess on my part. I tried compiling your code, saw some error output for undefined symbols and then based on the reported function name (and the help of the man command) I was able to guess what library provided the symbol.

5
  • Hey, tnx a lot for answering. I tryed to get older code and got this code from Bjarne Stroustrups book - Programming principles and practice using C++ and it also doesnt work. I cant include even the first header file. Edited my post
    – etrusks
    May 25, 2015 at 5:35
  • If you've installed fltk1.3-doc, then try copying some of the examples from that. They're in /usr/share/doc/fltk1.3-doc/examples/. Copy them out, run gunzip on them, and they should all compile with pretty much the same flags. Also, take a look at the PDF evince /usr/share/doc/fltk1.3-doc/fltk.pdf.gz
    – Stephen
    May 25, 2015 at 14:09
  • Thanks for your advice but it still didnt work. Compiled ur code with line lke this g++ fltk-config --cxxflags main.cpp fltk-config --libs -lX11 -ldl -lXext -lXinerama -lXft -lfontconfig -o snippet coz my cpp file is called main I got this error message /usr/bin/ld: cannot find -lXinerama collect2: error: ld returned 1 exit status Anyway man thank you very much for coming back here and editing your answer. Appreciate it!
    – etrusks
    May 25, 2015 at 15:29
  • Try removing the flag for xinerama or installing the xinerama dev package, I think it's x11proto-xinerama-dev and libxinerama1.
    – Stephen
    May 25, 2015 at 16:00
  • Thank you really much for your help man. For now i decided to improve my program with multithreading, only than will create some GUI. Than will have some good place to come to read this good info about FLTK again :)
    – etrusks
    May 27, 2015 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .