Re: [fltk.general] How I get and glue the FLTK dependecies in my application?

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: How I get and glue the FLTK dependecies in my application? Greg Ercolano 18:54 Jul 27 top right image
 


On 7/27/22 14: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?


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



    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).

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/fe49eaa2-1ca5-cec5-e5fb-dc313f3cab7d%40seriss.com.
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2022 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.