|
|
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.
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 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+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.
--
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/CALJRLyv1%2B%2BSS8wObGDeCEoPTY7hdojvfa_U_GyfmZ19LVWyovg%40mail.gmail.com.
[ Direct Link to Message ] | |
|
| |