Making a statically linked executable.

499 views
Skip to first unread message

bat

unread,
Feb 24, 2015, 6:26:51 PM2/24/15
to fltkg...@googlegroups.com
If I compile my app (mads.cxx) with fltk-config it works fine and generates this as the full-length command which I can save into a script...

g++ -I/usr/local/include -I/usr/local/include/FL/images -I/usr/include/freetype2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT -o 'mads' 'mads.cxx' /usr/local/lib/libfltk.a -lXcursor -lXfixes -lXext -lXft -lfontconfig -lXinerama -lpthread -ldl -lm -lX11

...but I am struggling to get this to accept a '-static' option so as to make a nice big transportable executable. Its not worth showing you the errors I am getting, I just need to know roughly where I should stick in the static command. I did work it out for MinGW, but my current problem relates to linux. 

Kevin Ingwersen (Ingwie Phoenix)

unread,
Feb 24, 2015, 6:34:50 PM2/24/15
to fltkg...@googlegroups.com
Use the $CXXFLAGS environment variable. At least fltk-config used to take note of that. :)

If not, then use the „where“ tool and edit the script

$ where fltk-config
$ editor (the path you just saw.)

--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

MacArthur, Ian (Selex ES, UK)

unread,
Feb 25, 2015, 12:08:15 PM2/25/15
to fltkg...@googlegroups.com
> If I compile my app (mads.cxx) with fltk-config it works fine and
> generates this as the full-length command which I can save into a
> script...

> g++ -I/usr/local/include -I/usr/local/include/FL/images
> -I/usr/include/freetype2 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
> -D_FILE_OFFSET_BITS=64 -D_THREAD_SAFE -D_REENTRANT -o 'mads' 'mads.cxx'
> /usr/local/lib/libfltk.a -lXcursor -lXfixes -lXext -lXft -lfontconfig
> -lXinerama -lpthread -ldl -lm -lX11

> ...but I am struggling to get this to accept a '-static' option so as to
> make a nice big transportable executable. Its not worth showing you the
> errors I am getting, I just need to know roughly where I should stick in
> the static command. I did work it out for MinGW, but my current problem
> relates to linux.

So... Why do you think you need the "-static" option here? I'm interested in what things you want to link in static.

I'd suggest that linking flkt in static is probably a good idea, as many systems when your could might run, will not have the fltk .so's available.

But the other things in your list (all the X11 stuff, fontconfig, etc.) you *do not* want to link in static at all, in all likelihood, since your *must* use the local system versions on each machine you run on, or there will be "issues".
In particular the X11 drivers are closely tied to the kernel, so using the X11 binaries linked on one system may not "play" well on another system at all.

Further, it's pretty much a given that these "system" .so's *do* exist, so you can rely on them...

Upshot? To link in the fltk libs static, you don't need to use the "-static" option at all; all you (usually) need to do is give the fully resolved path to the .a version of the fltk libs:

i.e., if you say:

g++ <stuff> -lfltk -letc...

Then the linker will look for *something" to fulfil the "-lfltk" and if it finds even a hint of an .so it will prefer to link that.

However, if you explicitly say:

g++ <stuff> /path/to/my/libfltk.a -letc...

Then it will use the static libfltk, and "all will be well"...

You can get the necessary values from fltk-config:

fltk-config --ldstaticflags

Will show you what you need.






Selex ES Ltd
Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL
A company registered in England & Wales. Company no. 02426132
********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

bat

unread,
Feb 25, 2015, 12:27:10 PM2/25/15
to fltkg...@googlegroups.com, ian.ma...@selex-es.com
Cheers Ingwie and Ian for all that. If I make a statically linked executable on windows I can send it to anyone and they can, more-or-less, just run it on any Windows system (with perhaps using the 'troubleshoot-compatibility' thing that the windows right-click provides) without having FLTK installed, etc. I would like to do the same with Linux, but my lack of experience is showing through again, and maybe I just don't need to - I will make some tests (except that our server is down... bah humbug). 

MacArthur, Ian (Selex ES, UK)

unread,
Feb 26, 2015, 10:36:29 AM2/26/15
to fltkg...@googlegroups.com
> If I make a statically linked
> executable on windows I can send it to anyone and they can,
> more-or-less, just run it on any Windows system (with perhaps using the
> 'troubleshoot-compatibility' thing that the windows right-click
> provides) without having FLTK installed, etc.

I don't think fltk uses any Win32 API that require you to run in compatibility mode.

What are you hitting that needs compatibility mode? I'd be interested to hear...



> I would like to do the same with Linux

This should be fairly straightforward (for certain values of straightforward...)

In general, I'd suggest you link against the fltk static lib (libfltk.a and etc.) but use the system shared objects for everything else, e.g. the X11 libs etc.

It is fairly reasonable to assume that any Linux box that wants to display a fltk GUI app, will have X11 running, and that any "recent" X11 setup will provide all the bits that fltk needs. (Fltk's needs are not that cutting edge in general...)

The tricky areas are around font handling; nowadays, I just assume that "everyone" has XFT and fontconfig, and that seems to work OK, but you might find some systems that do not. You can configure fltk to build without XFT - then it will fall back to the legacy Xlib font interface; this will probably work "everywhere", but look like s***. I'd suggest not doing that unless you really find you need to!
In any case, static linking fontconfig and XFT into your app is not likely to work well, as they need to match the underlying X setup pretty closely, and so you always want to use the system provided versions if possible.


Another thing that can throw you is GL support; this is sometimes patchy on Linux boxes (though things are better nowadays) but again static linking will not help you much here, as again you need to match the underlying system or it will not work.

Use a GL extension wrangler and have it check at runtime for what GL capabilities are available and code accordingly, I guess (though this is arguably true for portable GL code on nay host I guess!)

bat

unread,
Feb 26, 2015, 6:42:44 PM2/26/15
to fltkg...@googlegroups.com, ian.ma...@selex-es.com

What are you hitting that needs compatibility mode? I'd be interested to hear.

The FLTK stuff seems to work fine on windows but it is probably the shellexecuteinfo and/or shellexecuteex bits, for which I just copied something off the web (very dodgy), that cause compatibility issues. 

MacArthur, Ian (Selex ES, UK)

unread,
Feb 27, 2015, 5:23:57 AM2/27/15
to fltkg...@googlegroups.com
> > What are you hitting that needs compatibility mode?
> > I'd be interested to hear.

> The FLTK stuff seems to work fine on windows but it is
> probably the shellexecuteinfo and/or shellexecuteex bits,
> for which I just copied something off the web (very dodgy),
> that cause compatibility issues.


OK. Um... that sounds like it might be self-inflicted then...?

I advise always to have a good look at the MS docs on MSDN when "borrowing" any random WIN32 code you find on the web!

bat

unread,
Mar 13, 2015, 7:22:19 PM3/13/15
to fltkg...@googlegroups.com
I think it looks like I need to make some sort of makefile for my app which a user on another computer could then use to compile it themselves under linux and it would warn them what libraries are needed, etc, or can FLTK be bundled in somehow? I found clues on the web but a concrete example would be very helpful because makefiles have always a blackbox to me ;-0

Ian MacArthur

unread,
Mar 13, 2015, 7:26:04 PM3/13/15
to fltkg...@googlegroups.com
On Fri Mar 13 2015 23:22:19, bat wrote:
> I think it looks like I need to make some sort of makefile for my app which a user on another computer could then use to compile it themselves under linux and it would warn them what libraries are needed, etc, or can FLTK be bundled in somehow? I found clues on the web but a concrete example would be very helpful because makefiles have always a blackbox to me ;-0

You could start with this how to then build out form there, I think...

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





Reply all
Reply to author
Forward
0 new messages