How I get and glue the FLTK dependecies in my application?

28 views
Skip to first unread message

Daniel Silva

unread,
Jul 27, 2022, 5:30:14 PMJul 27
to fltk.general
I want more control of the compilation process, linking the fltk relative to my project folder, without having the install, because I want to stay up to date with the project and linking it staticly.
But it's pretty hard to get the necessery fltk dependecies to compile my application within my Makefile.
The fltk-config --ldflags doesn't return all necessery libs dependecies, but I noted the first definition of LDLIBS var inside the fltk-config has the dependecies, but I can't get it in a nicer way other than copy manually.
So my setup is a mess,  so I'm doing this completly wrong?


In the make folder I got the NMake Makefile.vc for windows and make Makefile for linux.

Thanks.

Greg Ercolano

unread,
Jul 27, 2022, 9:54:34 PMJul 27
to fltkg...@googlegroups.com



    Since you should compile your app with similar flags used to build FLTK
    (for consistency and library compatibility), fltk-config is used to output
    those flags used to last build fltk so you can use them in your Makefile.

    Generally the technique is to have your Makefile invoke fltk-config
    with various options to get at least these three things:

        1) $(CXX) -- the name of the compiler (e.g. g++)
        2) $(CXXFLAGS) -- the compiler flags
        3) $(LDFLAGS) -- the linker flags

    So a simple example:

     CXX=$(shell fltk-config --cxx)
CXXFLAGS=$(shell fltk-config --cxxflags)
 LDFLAGS=$(shell fltk-config --use-images --ldstaticflags)

    ..and then you'd compile and link your app with these simple Makefile targets:

# CREATE EXECUTABLE FROM OBJ
hello: hello.o
    $(CXX) hello.o $(LDFLAGS) -o hello

# COMPILE .cpp -> .obj
hello.o: hello.cpp
    $(CXX) $(CXXFLAGS) hello.cpp -c

    ..and together that makes a simple Makefile for an app called 'hello'.

    Since fltk-config is usually not in the PATH, and there might be several versions of
    FLTK on your drive, it's best to use a specific path to the fltk-config program,
    so you'd use this instead to set those three variables:

# Path to a specific FLTK version's fltk-config script
FLTKCONFIG=/usr/local/src/fltk-1.4.x-git/fltk-config

     CXX=$(shell $(FLTKCONFIG) --cxx)

CXXFLAGS=$(shell $(FLTKCONFIG) --cxxflags)

LDFLAGS=$(shell $(FLTKCONFIG) --use-images --ldstaticflags)

    That gets rid of any ambiguity for which version of FLTK is used, and your
    compile/link commands remain the same.

    So put that all together, and you end up with a fairly complete Makefile
    for linux/osx that looks like:


FLTKCONFIG=/usr/local/src/fltk-1.4.x-git/fltk-config
     CXX=$(shell $(FLTKCONFIG) --cxx)
CXXFLAGS=$(shell $(FLTKCONFIG) --cxxflags)
 LDFLAGS=$(shell $(FLTKCONFIG) --use-images --ldstaticflags)

# CREATE EXECUTABLE FROM OBJ
hello: hello.o
    $(CXX) hello.o $(LDFLAGS) -o hello

# COMPILE .cpp -> .obj
hello.o: hello.cpp
    $(CXX) $(CXXFLAGS) hello.cpp -c

clean:
    -/bin/rm hello.o hello


    This works (I just tested it on my Ubuntu machine).

    This is fine in a gnu make environment with a unixy compiler.
    On windows if you build your app with mingw/msys, you should
    be able to work similarly.

    I can't remember if there's a technique to do this in Windows with
    Visual Studio / NMAKE. If I remember correctly, nmake doesn't support
    a way to invoke an external program and pass the output to a variable
    the way $(shell) can in gnu make.

    However, a cmake build of FLTK might provide an NMAKE Makefile that
    you can use.. I think there's a README file in the fltk directory that's
    supposed to cover this.

    Offhand I'd guess that you can invoke fltk-config to output to small text files,
    and then use perl/sed/awk/whatever to jiggle those files into NMAKE syntax,
    and then 'include' those files in your NMAKE to set those variables..?

    I could swear either Ian or Matt wrote an article on all this, but I can't
    find it, so I made the above instead.

    I do see in the "FLTK Basics" section of the FLTK docs:
    https://www.fltk.org/doc-1.4/basics.html

    ..there's a section that covers building your own Makefiles, which is probably
    similar to the above, but I think it also discusses the new cmake stuff
    which may help with NMAKE, not sure. cmake is still relatively new to FLTK
    in 1.4, and is the preferred way to build FLTK on all platforms now (I think).

imm

unread,
Jul 28, 2022, 8:00:44 AMJul 28
to General FLTK
On Thu, 28 Jul 2022 at 02:54, Greg Ercolano wrote:
>
> I could swear either Ian or Matt wrote an article on all this, but I can't
> find it, so I made the above instead.
>

Might have been this?

https://www.fltk.org/articles.php?L599

FWIW it basically just says what you already said here though.

Albrecht Schlosser

unread,
Jul 28, 2022, 8:15:27 AMJul 28
to fltkg...@googlegroups.com
On 7/27/22 23:07 Daniel Silva wrote:
> I want more control of the compilation process, linking the fltk
> relative to my project folder, without having the install, because I
> want to stay up to date with the project and linking it staticly.
> But it's pretty hard to get the necessery fltk dependecies to compile
> my application within my Makefile.
> The fltk-config --ldflags doesn't return all necessery libs
> dependecies, but I noted the first definition of LDLIBS var inside the
> fltk-config has the dependecies, but I can't get it in a nicer way
> other than copy manually.
> So my setup is a mess,  so I'm doing this completly wrong?

Greg wrote a long answer that should cover what you need. Please read
this as well.

The short answer to your question *might* be that you should use
`fltk-config --ldstaticflags` rather than `fltk-config --ldflags`if you
want static linking.

If you look at Greg's recipe he's using ldstaticflags as well.

> https://github.com/daninsky1/inkbreaker
>
> In the make folder I got the NMake Makefile.vc for windows and make
> Makefile for linux.

I'm not sure how this would apply to NMake Makefiles though but hope it
helps.

imm

unread,
Jul 28, 2022, 8:18:22 AMJul 28
to General FLTK
Harking back to Daniels's original message, I'd strongly suggest never
installing a fltk you have built yourself, but always using it from
the build tree directly anyway. If nothing else it means there is no
danger of overwriting any system version that your distro may be
using...

Greg's note about setting a FLTKCONFIG var for your makefile is
sensible - I tend to set it as an environment variable, and then
change it depending on which fltk install I need for any given project
(I always have several fltk on the go...)

Daniel Silva

unread,
Jul 28, 2022, 10:24:38 AMJul 28
to fltkg...@googlegroups.com
Thank you.

However --ldstaticflags returns the fltk installation to link with "/usr/local/lib/libfltk.a", and doesn't return all the fltk dependencies, so I got linking errors.
--ldstaticflags returns "/usr/local/lib/libfltk.a -lXrender -lXft -lfontconfig -pthread -lpthread -lm -lX11"
But the first definition of LDLIBS var in fltk-config is "LDLIBS=" -lm -lX11 -lXext -lpthread -lXinerama -lXfixes -lXcursor -lXft -lXrender -lm -lfontconfig -ldl"
And works fine.

When I had this problem in Windows, at the time I didn't know about this script, so I linked manually with the system, which was pretty dum :x and painful haha.
The Windows problem I need to do something more clever too later, to get the dependencies and flags.

--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/vj6Z_3KufEw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/fe49eaa2-1ca5-cec5-e5fb-dc313f3cab7d%40seriss.com.

Greg Ercolano

unread,
Jul 28, 2022, 11:27:03 AMJul 28
to fltkg...@googlegroups.com

On 7/28/22 07:12, Daniel Silva wrote:

Thank you.

However --ldstaticflags returns the fltk installation to link with "/usr/local/lib/libfltk.a", and doesn't return all the fltk dependencies, so I got linking errors.
--ldstaticflags returns "/usr/local/lib/libfltk.a -lXrender -lXft -lfontconfig -pthread -lpthread -lm -lX11"
But the first definition of LDLIBS var in fltk-config is "LDLIBS=" -lm -lX11 -lXext -lpthread -lXinerama -lXfixes -lXcursor -lXft -lXrender -lm -lfontconfig -ldl"
And works fine.

    Here's what I get when I run fltk-config and use just --ldstaticflags:
# /usr/local/src/fltk-1.4.x-git/fltk-config --ldstaticflags
/usr/local/src/fltk-1.4.x-git/lib/libfltk.a -lXrender -lXcursor -lXfixes -lXft -lfontconfig -lXinerama -pthread -lpthread -ldl -lm -lX11
   ..which looks a lot like your correct flags.

    IMPORTANT: Are you sure your Makefile is invoking fltk-config with an absolute path
    to the fltk-config in your app dir? e.g. /usr/you/project/fltk-1.4.x/fltk-config
    It doesn't have to be an absolute path, it can be relative. Just as long
    as it points to the specific version of FLTK your app is trying to build with.

    If you're just running 'fltk-config' (without a path), then you're probably picking up
    whatever random version of FLTK that's installed on your machine and is in your PATH,
    and that probably has very different build flags that are wrong for your app.

    Point make to the correct fltk-config script, as there will be one fltk-config for
    each version of FLTK, so you have to run the matching one to the one you're
    compiling and linking against.

    Also, if you have a version of fltk installed as part of the OS on your machine
    (e.g. with 'apt' or 'yum'), then be sure when you have #include <FL/Fl.H>
    in your code that it's not picking up /usr/include/FL, as that might not be
    compatible with the FLTK you want to build with. This is why Ian suggested
    you do not install FLTK on a machine (yum/apt/etc) if you're working with
    multiple FLTK versions; it can create all kinds of problems when #include files
    picked up during compile (e.g. /usr/include/FL) don't match the fltk libraries
    you're linking with (e.g. /some/where/yourproject/fltk-1.4.x/..)


Daniel Silva

unread,
Jul 28, 2022, 11:28:14 AMJul 28
to fltkg...@googlegroups.com
Thank you.

Ye sure, that's more precise.
However I'm not interested in the fltk lib --ldflags or --ldstaticflags returns, because I'm linking manually to the static fltk lib to my fltk build, what I looking for is the fltk, I think, shared system dependencies.
Both of these options return the same list of fltk dependencies flags, but not all.

--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/vj6Z_3KufEw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.

Daniel Silva

unread,
Jul 28, 2022, 11:28:14 AMJul 28
to fltkg...@googlegroups.com
Ye, I agree. In my case I want my project and dependencies to live in the project dir. And not affect anything in the system if possible.

--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/vj6Z_3KufEw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.

Greg Ercolano

unread,
Jul 28, 2022, 12:14:43 PMJul 28
to fltkg...@googlegroups.com

On 7/28/22 07:37, Daniel Silva wrote:

However I'm not interested in the fltk lib --ldflags or --ldstaticflags returns,
because I'm linking manually to the static fltk lib to my fltk build,

    Hmm, but what you say you want sounds exactly like what
    --ldstaticflags is meant for.

    It returns the static version of fltk's lib and the system dependencies.

    So just be sure to not specify libfltk.a in your Makefile, and let --ldstaticflags
    specify it for you.

    I think the problem you're having with --ldstaticflags returning unexpected results
    is a different issue, perhaps due to picking up the wrong fltk-config script.

    --ldstaticflags is probably what you should use, me thinks.

    Try a simple test with something small; create a new project directory.
    Then create a simple hello.cpp file in that directory:
#include <FL/Fl_Double_Window.H>
int main() {
    Fl_Double_Window win(200,200,"test");
    win.show();
    return Fl::run();
}
    Then create a Makefile, with an FLTKCONFIG line at the top that
    points to the fltk-1.4.x directory of your other project, e.g.
FLTKCONFIG=/path/to/your/other/project/fltk-1.4.x/fltk-config

       CXX=$(shell $(FLTKCONFIG) --cxx)
  CXXFLAGS=$(shell $(FLTKCONFIG) --cxxflags)
   LDFLAGS=$(shell $(FLTKCONFIG) --ldstaticflags)


# CREATE EXECUTABLE FROM OBJ
hello: hello.o
    $(CXX) hello.o $(LDFLAGS) -o hello

# COMPILE .cpp -> .obj
hello.o: hello.cpp
    $(CXX) $(CXXFLAGS) hello.cpp -c

clean:
    -/bin/rm hello.o hello
    Then try 'make'. It should build hello and link with FLTK statically
    using the FLTK library your other project is using.

    It should work, assuming that version of FLTK was built recently
    on this operating system.

Daniel Silva

unread,
Jul 28, 2022, 12:44:00 PMJul 28
to fltkg...@googlegroups.com
-_-, gee, you are right.

I remember I tried to pull the relative and got an error from my fish shell, and I didn't investigate(maybe I typed wrong or maybe fltk build was clean), I think when I pulled the system one in my head it was coming from the relative path, without realizing that I was not using either the absolute or relative path to the RIGHT script.
Greg, thank you for your time.

--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/vj6Z_3KufEw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.

anmol....@gmail.com

unread,
Oct 31, 2022, 11:04:37 PMOct 31
to fltk.general
Hi Greg.
I'm using this Makefile in Ubuntu on WSL2.
I can use fltk-config to build a shared file e.g. fltk-config --compile hello.cxx
However, for the static libs I get these errors. Any ideas?
apt tells me that xinerama et all are installed

/usr/bin/ld: cannot find -lXrender
/usr/bin/ld: cannot find -lXcursor
/usr/bin/ld: cannot find -lXft
/usr/bin/ld: cannot find -lfontconfig
/usr/bin/ld: cannot find -lXinerama

anmol....@gmail.com

unread,
Oct 31, 2022, 11:34:51 PMOct 31
to fltk.general
All good. We needed xorg-dev

sudo apt-get install xorg-dev 

Thanks for the portable Makefile setup. 

Greg Ercolano

unread,
Oct 31, 2022, 11:42:25 PMOct 31
to fltkg...@googlegroups.com

On 10/31/22 20:04, anmol....@gmail.com wrote:

Hi Greg.
I'm using this Makefile in Ubuntu on WSL2.
I can use fltk-config to build a shared file e.g. fltk-config --compile hello.cxx
However, for the static libs I get these errors. Any ideas?
apt tells me that xinerama et all are installed

/usr/bin/ld: cannot find -lXrender
/usr/bin/ld: cannot find -lXcursor
/usr/bin/ld: cannot find -lXft
/usr/bin/ld: cannot find -lfontconfig
/usr/bin/ld: cannot find -lXinerama

    I'm not familiar with WSL aspect of your setup, but with ubuntu to build
    e.g. fltk or fltk apps, you should make sure X development libs are installed.

    I can't remember if Ubuntu's apt system supports the "package group" concept
    that the redhat/yum does, and if there is a package group that installs all that stuff
    with a single group name. I think in my case on ubuntu, I did an apt search for each
    of those to see if there was a lib dev package, and just installed them one by one
    using 'apt install'.

    Right now on my ubuntu 20 dev box, I'm seeing I installed these libx11 dev
    libs which is probably what you need:

libx11-dev/focal-updates,focal-security,now 2:1.6.9-2ubuntu1.2 amd64 [installed]
libxcursor-dev/focal,now 1:1.2.0-2 amd64 [installed]
libxft-dev/focal,now 2.3.3-0ubuntu1 amd64 [installed]
libxft2/focal,now 2.3.3-0ubuntu1 amd64 [installed]
libxrender-dev/focal,now 1:0.9.10-1 amd64 [installed]
libxt-dev/focal,now 1:1.1.5-1 amd64 [installed]

    ..so for you to replicate that, I imagine it'd be:
sudo apt install libx11-dev libxcursor-dev libxft-dev libxft2 libxrender-dev libxt-dev

Reply all
Reply to author
Forward
0 new messages