Compile a FLTK app through a makefile ?

247 views
Skip to first unread message

Lucas Sanner

unread,
Mar 27, 2023, 7:50:44 AM3/27/23
to fltk.general
Hi all,

I'm trying to compile the basic FLTK example available here: https://www.fltk.org/doc-1.3/basics.html
It works fine with the command line:
fltk-config --compile hello.cpp

But when I try to compile through my makefile:

SRC = hello.cpp
CXX = g++
CXXFLAGS = -Wall

LFLAGS = $(shell fltk-config --ldstaticflags)

OBJS = $(SRC:.cpp=.o)

%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $(<) -o $(@)

EXE = hello

all: $(EXE)

$(EXE): $(OBJS)
$(CXX) -o $@ $^ $(LFLAGS)

%.o: %.cpp *.h
 $(CXX) -o $@ -c $< $(CXXFLAGS)

depend:
makedepend -- $(CXXFLAGS) -- $(SRC)

strip: $(EXE
strip --strip-all $(EXE)

clean:
del $(EXE)

I get the following errors:

g++ -o hello hello.o /usr/lib/x86_64-linux-gnu/libfltk.a -lXrender -lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lpthread -lm  -lX11
/usr/bin/ld: cannot find -lXrender: No such file or directory
/usr/bin/ld: cannot find -lXcursor: No such file or directory
/usr/bin/ld: cannot find -lXfixes: No such file or directory
/usr/bin/ld: cannot find -lXext: No such file or directory
/usr/bin/ld: cannot find -lXft: No such file or directory
/usr/bin/ld: cannot find -lfontconfig: No such file or directory
/usr/bin/ld: cannot find -lXinerama: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [makefile:35: hello] Error 1

How can I fix this problem ?

Albrecht Schlosser

unread,
Mar 27, 2023, 8:56:18 AM3/27/23
to fltkg...@googlegroups.com
On 3/27/23 11:12 Lucas Sanner wrote:
I'm trying to compile the basic FLTK example available here: https://www.fltk.org/doc-1.3/basics.html
It works fine with the command line:
fltk-config --compile hello.cpp

But when I try to compile through my makefile:

[...]



I get the following errors:

g++ -o hello hello.o /usr/lib/x86_64-linux-gnu/libfltk.a -lXrender -lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lpthread -lm  -lX11
/usr/bin/ld: cannot find -lXrender: No such file or directory
/usr/bin/ld: cannot find -lXcursor: No such file or directory
/usr/bin/ld: cannot find -lXfixes: No such file or directory
/usr/bin/ld: cannot find -lXext: No such file or directory
/usr/bin/ld: cannot find -lXft: No such file or directory
/usr/bin/ld: cannot find -lfontconfig: No such file or directory
/usr/bin/ld: cannot find -lXinerama: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [makefile:35: hello] Error 1

How can I fix this problem ?

Did you really copy/paste your full Makefile in your message? If I try your Makefile I get different errors.

First of all a syntax error (missing bracket at end of "$(EXE"):
Makefile-test:25: *** unterminated variable reference.  Stop.

After that I got another error because you missed to add the required CXXFLAGS for FLTK:
g++ -Wall -c hello.cpp -o hello.o
hello.cpp:17:10: fatal error: FL/Fl.H: No such file or directory
   17 | #include <FL/Fl.H>
      |          ^~~~~~~~~

After adding the FLTK CXXFLAGS to the "CXXFLAGS" variable everything works fine for me.

Modified Makefile:

```
SRC = hello.cpp
CXX = g++
CXXFLAGS = -Wall $(shell fltk-config --cxxflags)
LFLAGS = $(shell fltk-config --ldstaticflags)
OBJS = $(SRC:.cpp=.o)
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $(<) -o $(@)
EXE = hello
all: $(EXE)
$(EXE): $(OBJS)
$(CXX) -o $@ $^ $(LFLAGS)
%.o: %.cpp *.h
$(CXX) -o $@ -c $< $(CXXFLAGS)
depend:
makedepend -- $(CXXFLAGS) -- $(SRC)
strip: $(EXE)
strip --strip-all $(EXE)
clean:
rm -f $(EXE)

```

I also changed 'del' to 'rm' because 'del' isn't known on Linux which I assume you're using.

If you have further questions, please tell us your OS, version, and FLTK version.

Lucas Sanner

unread,
Mar 27, 2023, 10:17:12 AM3/27/23
to fltk.general
Thanks for your help.


> Did you really copy/paste your full Makefile in your message?
Yes I did, but maybe an error sneaked during the process.

Unfortunately I copy paste your modified makefile and I still get the same error.

g++ -Wall -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16  -c hello.cpp -o hello.o

g++ -o hello hello.o /usr/lib/x86_64-linux-gnu/libfltk.a -lXrender -lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lpthread -lm  -lX11
/usr/bin/ld: cannot find -lXrender: No such file or directory
/usr/bin/ld: cannot find -lXcursor: No such file or directory
/usr/bin/ld: cannot find -lXfixes: No such file or directory
/usr/bin/ld: cannot find -lXext: No such file or directory
/usr/bin/ld: cannot find -lXft: No such file or directory
/usr/bin/ld: cannot find -lfontconfig: No such file or directory
/usr/bin/ld: cannot find -lXinerama: No such file or directory
collect2: error: ld returned 1 exit status
make: *** [makefile:17: hello] Error 1

Any idea where this problem comes from ?

OS: Ubuntu 22.04
FLTK version: 1.3.8

Matthias Melcher

unread,
Mar 27, 2023, 10:17:43 AM3/27/23
to fltk.general
You need to install those missing libraries. It’s described in detail in README.Unix.txt

Albrecht Schlosser

unread,
Mar 27, 2023, 10:20:59 AM3/27/23
to fltkg...@googlegroups.com
On 3/27/23 16:17 'Matthias Melcher' via fltk.general wrote:
> You need to install those missing libraries. It’s described in detail
> in README.Unix.txt

That was my first thought as well, but Lucas wrote that it worked with
`fltk-config --compile` which rules out missing libraries. There must be
something else going on...

Albrecht Schlosser

unread,
Mar 27, 2023, 10:36:58 AM3/27/23
to fltkg...@googlegroups.com
On 3/27/23 15:56 Lucas Sanner wrote:
> Thanks for your help.

Welcome.

> Unfortunately I copy paste your modified makefile and I still get the
> same error.
>
> g++ -Wall -I/usr/include/cairo -I/usr/include/glib-2.0
> -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
> -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
> -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
> -I/usr/include/cairo -I/usr/include/glib-2.0
> -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
> -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
>  -c hello.cpp -o hello.o
> g++ -o hello hello.o /usr/lib/x86_64-linux-gnu/libfltk.a -lXrender
> -lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lpthread -lm
>  -lX11
> /usr/bin/ld: cannot find -lXrender: No such file or directory
> /usr/bin/ld: cannot find -lXcursor: No such file or directory
> /usr/bin/ld: cannot find -lXfixes: No such file or directory
> /usr/bin/ld: cannot find -lXext: No such file or directory
> /usr/bin/ld: cannot find -lXft: No such file or directory
> /usr/bin/ld: cannot find -lfontconfig: No such file or directory
> /usr/bin/ld: cannot find -lXinerama: No such file or directory
> collect2: error: ld returned 1 exit status
> make: *** [makefile:17: hello] Error 1
>
> Any idea where this problem comes from ?

Unfortunately not. But I have more questions...

> OS: Ubuntu 22.04
> FLTK version: 1.3.8

Are you using an installed version (i.e. an Ubuntu package) of FLTK
1.3.8, or did you build it yourself? If yes, did you "install" it, or
are you using it directly on the source or build directory?

Please make sure that you have only one version of FLTK installed,
mixing different versions can have strange effects. However, this
doesn't seem the issue here.

Please post your *working* command (using `fltk-config`) and its full
output. What is different? Certainly it's only a single command to
compile and link, but that's no problem. Different compiler and linker
switches would be more important.

Please post also the result of `which fltk-config` on your system.

If you built FLTK yourself, please tell us how (configure/make, CMake)
and the full build command.

If you did not "install" FLTK after building, please use an explicit
path to fltk-config for further tests and in your Makefile, just to make
sure you're not using an installed version, e.g. "./fltk-config
--compile hello.cpp".

Lucas Sanner

unread,
Mar 27, 2023, 11:05:05 AM3/27/23
to fltk.general
Thanks again.
It works now after installing the following libraries:
sudo apt-get install libxcursor-dev
sudo apt-get install libxinerama-dev
sudo apt-get install libxft-dev

However, as Albrecht has pointed it out, I don't understand why these libraries are not required when using the --compile option:
fltk-config --compile hello.cpp

Albrecht Schlosser

unread,
Mar 27, 2023, 11:12:12 AM3/27/23
to fltkg...@googlegroups.com
On 3/27/23 16:43 Lucas Sanner wrote:
> Thanks again.
> It works now after installing the following libraries:
> sudo apt-get install libxcursor-dev
> sudo apt-get install libxinerama-dev
> sudo apt-get install libxft-dev

OK, great!

> However, as Albrecht has pointed it out, I don't understand why these
> libraries are not required when using the --compile option:
> fltk-config --compile hello.cpp

It is possible that you have different FLTK versions and that these two
versions have been built with different dependencies. That's why I asked
you more questions about your system, e.g. what `which fltk-config`
outputs. If this is different than your compiled/built/installed version
(e.g. an FLTK package from Ubuntu) then this may be the case. Also,
using an explicit path to the built/installed FLTK version may help.
Note that `fltk-config` w/o explicit path likely runs the installed
system version (but this is also true if you use it w/o path in the
Makefile).


Lucas Sanner

unread,
Mar 27, 2023, 11:17:32 AM3/27/23
to fltk.general
> Are you using an installed version
Yes, I simply installed the package:
sudo apt install libfltk1.3-dev


> Please make sure that you have only one version of FLTK installed
As far as I know, the only version I have is the one I installed.


>Please post your *working* command (using `fltk-config`) and its full output.
Usage: fltk-config [OPTIONS]
Options:
        [--version]
        [--api-version]

Options telling what we are doing:
        [--use-gl]        use GL
        [--use-images]    use extra image formats (PNG, JPEG)
        [--use-glut]      use glut compatibility layer
        [--use-forms]     use forms compatibility layer
        [--use-cairo]     use cairo graphics lib

Options telling what information we request:
        [--cc]            return C compiler used to compile FLTK
        [--cxx]           return C++ compiler used to compile FLTK
        [--optim]         return compiler optimization used to compile FLTK
        [--cflags]        return flags to compile C using FLTK
        [--cxxflags]      return flags to compile C++ using FLTK
        [--ldflags]       return flags to link against FLTK
        [--ldstaticflags] return flags to link against static FLTK library
                                          even if there are DSOs installed
        [--libs]          return FLTK libraries full path for dependencies
        [--prefix]        return FLTK install time --prefix directory
        [--includedir]    return FLTK install time include directory

Options to compile and link an application:
        [-g]              compile the program with debugging information
        [-Dname[=value]]  compile the program with the given define
        [--compile program.cxx]
        [--post program]  prepare the program for desktop use

fltk-config --version
1.3.8


> Please post also the result of `which fltk-config` on your system
/usr/bin/fltk-config

Albrecht Schlosser

unread,
Mar 27, 2023, 5:00:37 PM3/27/23
to fltkg...@googlegroups.com
On 3/27/23 17:17 Lucas Sanner wrote:
> > Are you using an installed version
> Yes, I simply installed the package:
> sudo apt install libfltk1.3-dev

OK.

>
> > Please make sure that you have only one version of FLTK installed
> As far as I know, the only version I have is the one I installed.

OK.

> >Please post your *working* command (using `fltk-config`) and its full
> output.

Oh, sorry, I was not clear. I meant the command you used to compile
hello.cpp with fltk-config, probably
```
$ fltk-config --compile hello.cpp
```

The output of this "*working* fltk-config command" (as you wrote) is
what I'm interested in.

Please post this.

>
> fltk-config --version
> 1.3.8
>
> > Please post also the result of `which fltk-config` on your system
> /usr/bin/fltk-config

Yes, that's what I would assume. If this is the only installed FLTK
version, using just 'fltk-config ...' w/o an explicit path should be fine.


Lucas Sanner

unread,
Mar 28, 2023, 4:08:03 AM3/28/23
to fltk.general
> Oh, sorry, I was not clear. I meant the command you used to compile
Ok, no problem. Here it is:

$ fltk-config --compile hello.cpp
g++ -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fvisibility-inlines-hidden -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -o 'hello' 'hello.cpp' -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -lfltk -lX11

Albrecht Schlosser

unread,
Mar 28, 2023, 8:07:53 AM3/28/23
to fltkg...@googlegroups.com
On 3/28/23 10:08 Lucas Sanner wrote:
> > Oh, sorry, I was not clear. I meant the command you used to compile
> Ok, no problem. Here it is:
>
> $ fltk-config --compile hello.cpp
> g++ -I/usr/include/cairo -I/usr/include/glib-2.0
> -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
> -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
> -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
> -I/usr/include/cairo -I/usr/include/glib-2.0
> -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1
> -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16
> -g -O2 -fstack-protector-strong -Wformat -Werror=format-security
> -fvisibility-inlines-hidden -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
> -D_THREAD_SAFE -D_REENTRANT -o 'hello' 'hello.cpp'
> -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -lfltk -lX11

Thanks. If you look at the end of the command above, you see "-lfltk
-lX11". I assume that Ubuntu provides a shared FLTK library (-lfltk) and
this one automatically links (or better: loads at program startup) the
required libs.

Your Makefile uses `fltk-config --ldstaticflags` which links the FLTK
object library libfltk.a which requires to also link the "other" X11
libs. So, to resolve the issue in the first place you could have changed
"--ldstaticflags" to "--ldflags" and this *should* have worked. On your
system. Or maybe not.

The commands you posted from your `fltk-config --compile ...` and those
of the Makefile seem to differ in some other aspects (compiler flags).
This may indicate that the Ubuntu folks patched their version of
fltk-config in unintended ways.

Hence it's hard to find out why something doesn't work on a particular
user system (yours) if one doesn't have all informations. But I believe
we got it now.

Lucas Sanner

unread,
Mar 28, 2023, 10:49:25 AM3/28/23
to fltk.general
>Your Makefile uses `fltk-config --ldstaticflags` which links the FLTK
>object library libfltk.a which requires to also link the "other" X11
>libs. So, to resolve the issue in the first place you could have changed
>"--ldstaticflags" to "--ldflags" and this *should* have worked. On your
>system. Or maybe not.

This could explain why I experienced problems compiling through my makefile.
Even though it's not one hundred percent sure it's a good lead anyway.
Thanks again for your help.
Reply all
Reply to author
Forward
0 new messages