Using fltk in an Autotools project

128 views
Skip to first unread message

david allen

unread,
May 10, 2019, 3:51:13 PM5/10/19
to fltk.general
I am wanting to convert a project to Autotools. I am new to Autotools, so I am starting with trying to compile and link hello.cxx from the fltk docs. My project directory has a single subdirectory src which contains hello.cxx and Makefile.am:

bin_PROGRAMS    = pkmods
pkmods_SOURCES  = hello.cxx
pkmods_LDAPP    = `fltk-config --ldflags`

The last line is very wrong.  I need help.

Albrecht Schlosser

unread,
May 11, 2019, 5:53:12 AM5/11/19
to fltkg...@googlegroups.com
This question is OT in fltk.general, although you ask how to build a
program using FLTK. FLTK uses autotools to create a configure script,
but we don't use automake, hence I'm afraid you won't get much help
here. You'd better ask in a mailing list / forum that handles autotools.

That said, many projects are migrating from autotools to CMake, and so
does FLTK, although we still provide configure/make.

Is there any reason you /need/ to use autotools? If not I'd suggest to
familiarize yourself with CMake which is *much* easier to understand and
you can use it for many platforms including Windows (Visual Studio) that
autotools don't support.

As a first step to using CMake to build a simple 'hello' project with
FLTK you might want to take a look at README.CMake.txt in the FLTK
distribution. HTH

Manolo

unread,
May 11, 2019, 11:30:36 AM5/11/19
to fltk.general
I believe there was an automake/autotools inversion
in a sentence of the post above. One should rather read:

    FLTK uses automake to create a configure script,
   but we don't use autotools, ...

Albrecht Schlosser

unread,
May 11, 2019, 12:16:14 PM5/11/19
to fltkg...@googlegroups.com
On 11.05.2019 17:30 Manolo wrote:
> I believe there was an automake/autotools inversion
> in a sentence of the post above. One should rather read:
>
>     FLTK uses _automake_ to create a configure script,
>    but we don't use _autotools_, ...

No, the wording was intentional, although not entirely correct.

'autotools' is, AFAICT, a generic term for all auto* tools. This
includes autoconf which we use to generate the configure script.

'automake' is one of the autotools to "Generate Makefile.in for
configure from Makefile.am" (see `man automake') which we don't use for
this case.

However, we do indeed use automake (thanks for the correction) in a
border case to generate "missing" support files for autoconf
(config.guess and config.sub) but this is entirely optional: you don't
need to install automake because there's a fallback to use the bundled
files from misc/ instead (misc/config.guess and misc/config.sub).

$ automake --add-missing
configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
automake: error: no 'Makefile.am' found for any configure output
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

All these errors are benign (ignored) because we don't really *use*
automake (to generate Makefiles).

david allen

unread,
May 12, 2019, 12:44:11 PM5/12/19
to fltk.general
I appreciate the advice. I had not considered cmake --- I had sort of thought it was more Windows related. Anyway, I have some ideas to pursue.

Bob Johnson

unread,
May 29, 2019, 4:42:44 AM5/29/19
to fltk.general
What I do with my autotools build is run the FLTK config in configure.ac and then use the output in Makefile.am:

# Configure bundled libraries
dnl The bundled FLTK library is configured here. OpenGL and NanoSVG are
dnl enabled by default. Cairo and Pango are not. If the latter are needed,
dnl pass '--enable-cairo' and '--enable-pango' on the configure command line.
dnl This configure.ac will also need to be updated to find the cairo/pango libs
dnl as the fltk-config library paths for glib are incorrect.
AC_MSG_NOTICE([
    --------------------------------------
          Configuring bundled FLTK
    --------------------------------------])
if [[ -x $srcdir/fltk/autogen.sh ]]; then
    (cd $srcdir/fltk; export NOCONFIGURE=1; ./autogen.sh; ./configure)
else
    AC_MSG_ERROR([cannot find FLTK library])
fi

dnl As FLTK is statically linked and has its own custom pkg-config,
dnl these variables must be defined here for later use in the Makefile.
dnl Note: if cairo is enabled, use --cflags instead of -cxxflags, as
dnl fltk-config hardcodes erroneous glib paths for the latter.
if [[ -x $srcdir/fltk/fltk-config ]]; then
    FLTK_INCLUDE="$($srcdir/fltk/fltk-config --cxxflags)";
    FLTK_LIB="$($srcdir/fltk/fltk-config --use-gl --use-images --ldflags)";
else
    AC_MSG_ERROR([fltk-config not found])
fi
AC_SUBST([FLTK_INCLUDE])
AC_SUBST([FLTK_LIB])

In Makefile.am use the variables defined in configure.ac:

pkmods_CPPFLAGS = (your flags) @$FLTK_INCLUDE@
pkmods_LDADD = (your flags) @$FLTK_LIB@

You'll also need to build the static library before your app:
BUILT_SOURCES = $(srcdir)/fltk/lib/libfltk.a
$(srcdir)/fltk/lib/libfltk.a:
        cd $(srcdir)/fltk && $(MAKE)

(In my project fltk is a git submodule off the main project directory, hence $(srcdir). Change as necessary.)

david allen

unread,
May 29, 2019, 11:21:38 AM5/29/19
to fltk.general
Thanks. I will have a go with this.
Reply all
Reply to author
Forward
0 new messages