FLTK

79 views
Skip to first unread message

Mark Summerfield

unread,
Nov 22, 2021, 4:13:38 AM11/22/21
to The Meson Build System
I'm just starting out with meson.
I can build 'hello.cpp' console app with no problem.
But I'd now like to create an FLTK app (on Linux).
I have locally installed FLTK in `~/opt/fltk13` and I have `fltk-config` (which works just like `pkg-config`) in my `PATH`.

How do I tell meson to use `fltk-config`?

Thanks.

Eli Schwartz

unread,
Nov 22, 2021, 7:18:59 AM11/22/21
to meson...@googlegroups.com
On 11/22/21 4:13 AM, 'Mark Summerfield' via The Meson Build System wrote:
> I'm just starting out with meson.
> I can build 'hello.cpp' console app with no problem.
> But I'd now like to create an FLTK app (on Linux).
> I have locally installed FLTK in `~/opt/fltk13` and I have `fltk-config`
> (which works just like `pkg-config`) in my `PATH`.


Unfortunately, fltk-config does NOT work just like pkg-config, that is
why pkg-config itself exists. :) The best long-term solution would be to
persuade upstream to implement this:

https://github.com/fltk/fltk/issues/22
https://www.fltk.org/str.php?L2180


> How do I tell meson to use `fltk-config`?


Since you don't have a proper pkg-config file, you'll need to jump
through a couple hoops:

fltk_config = find_program('fltk-config')

fltk_cflags = run_command(fltk_config, '--cflags', check:
true).stdout().strip()
fltk_libs = run_command(fltk_config, '--libs', check: true).stdout().strip()

fltk_dep = declare_dependency(compile_args: fltk_cflags, link_args:
fltk_libs)


--
Eli Schwartz

Mark

unread,
Nov 22, 2021, 8:02:50 AM11/22/21
to The Meson Build System
That got me a lot further, but I can't get the fltk 'hello world' to build (even though the test/demo works fine).
```
$ meson setup unix
The Meson build system
Version: 0.60.1
Source dir: /home/mark/app/cpp/hello-fltk
Build dir: /home/mark/app/cpp/hello-fltk/unix
Build type: native build
Project name: hello fltk
Project version: 0.1.0
C++ compiler for the host machine: c++ (gcc 9.3.0 "c++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0")
C++ linker for the host machine: c++ ld.bfd 2.34
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program fltk-config found: YES (/home/mark/opt/bin/fltk-config)
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Found CMake: /usr/bin/cmake (3.16.3)
Run-time dependency x11 found: YES
Build targets in project: 1

Found ninja-1.10.0 at /usr/bin/ninja
$ meson compile -C unix
ninja: Entering directory `/home/mark/app/cpp/hello-fltk/unix'
[2/2] Linking target hellofltk
FAILED: hellofltk
c++  -o hellofltk hellofltk.p/hello.cpp.o -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group /home/mark/opt/fltk14/lib/libfltk.a /usr/lib/x86_64-linux-gnu/libX11.so -Wl,--end-group
/usr/bin/ld: /home/mark/opt/fltk14/lib/libfltk.a(Fl_X11_Window_Driver.o): undefined reference to symbol 'dlsym@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
```
Note that fltk is normally statically linked.

Mark

unread,
Nov 22, 2021, 8:03:50 AM11/22/21
to The Meson Build System
Sorry forgot to include my `meson.build`:
```
project('hello fltk', 'cpp', version: '0.1.0')


fltk_config = find_program('fltk-config')
fltk_include_dirs = run_command(fltk_config, '--includedir',
                    check: true).stdout().strip()
fltk_cxxflags = run_command(fltk_config, '--cxxflags',
              check: true).stdout().strip()
fltk_link_args = run_command(fltk_config, '--libs',
                 check: true).stdout().strip()
fltk_dep = declare_dependency(compile_args: fltk_cxxflags,
                  include_directories: fltk_include_dirs,
                  link_args: fltk_link_args)
x11_dep = dependency('X11')

executable('hellofltk', 'hello.cpp', dependencies: [fltk_dep, x11_dep])
```

Dan Kegel

unread,
Nov 22, 2021, 9:36:48 AM11/22/21
to Mark, The Meson Build System
fltk_config seems to have left out -ldl, try jamming that in.

--
You received this message because you are subscribed to the Google Groups "The Meson Build System" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mesonbuild+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mesonbuild/d50492fc-620f-460d-93bd-ed572d458e56n%40googlegroups.com.

Mark

unread,
Nov 22, 2021, 11:12:47 AM11/22/21
to The Meson Build System
I'd be happy to try `-ldl` but don't know how to add that to my `meson.build`. I'm looking through the docs which I find v. frustrating.

Mark

unread,
Nov 22, 2021, 11:23:27 AM11/22/21
to The Meson Build System
I think I found how to add it so now my `meson.build` is:
```
project('hello fltk', 'cpp', version: '0.1.0')

fltk_config = find_program('fltk-config')
fltk_include_dirs = run_command(fltk_config, '--includedir', check: true).stdout().strip()
fltk_cxxflags = run_command(fltk_config, '--cxxflags', check: true).stdout().strip()
fltk_link_args = run_command(fltk_config, '--libs', check: true).stdout().strip()
fltk_dep = declare_dependency(compile_args: fltk_cxxflags,
                  include_directories: fltk_include_dirs,
                  link_args: fltk_link_args)

cc = meson.get_compiler('cpp')
dl_dep = cc.find_library('dl')


x11_dep = dependency('X11')

executable('hellofltk', 'hello.cpp', dependencies: [fltk_dep, dl_dep, x11_dep])
```
It still won't build but I think from the output that I need to add more dependencies, this time maybe on Xft.

[snip]

Anyway, thanks for your help.

Eli Schwartz

unread,
Nov 22, 2021, 4:01:15 PM11/22/21
to meson...@googlegroups.com
On 11/22/21 11:23 AM, 'Mark' wrote:
> It still won't build but I think from the output that I need to add
> more dependencies, this time maybe on Xft.


I took a look at the actual fltk-config program. It seems for some
strange reason you need to use both --libs and --ldflags, the latter
contains all the libs for the dependencies it needs.

I also made a terrible mistake before. You need to use .strip() on all
the outputs of run_command, to ensure that they get split on whitespace
and turned into arrays.


project('hello fltk', 'cpp', version: '0.1.0')

fltk_config = find_program('fltk-config')
fltk_include_dirs = run_command(fltk_config, '--includedir', check:
true).stdout().strip().split()
fltk_cxxflags = run_command(fltk_config, '--cxxflags', check:
true).stdout().strip().split()
fltk_link_args = run_command(fltk_config, '--ldflags', '--libs', check:
true).stdout().strip().split()
fltk_dep = declare_dependency(compile_args: fltk_cxxflags,
include_directories: fltk_include_dirs,
link_args: fltk_link_args)

cc = meson.get_compiler('cpp')

executable('hellofltk', 'hello.cpp', dependencies: [fltk_dep])


Again, if they just provided pkg-config files upstream then you wouldn't
need to struggle with this, it would just be:

fltk_dep = dependency('fltk')

and it would correctly figure out include directories, libs,
dependencies, everything all for you. Instead they have a non-standard
shell script which is confusing to use, and likely doesn't handle
cross-compiling correctly.


--
Eli Schwartz
Reply all
Reply to author
Forward
0 new messages