Which flags use, to compile FLTK project, without adding dll's inside the exe file (Windows)

66 views
Skip to first unread message

Mich Paw

unread,
Apr 16, 2017, 6:47:49 AM4/16/17
to fltk.general
Hello.

I'd like to compile project, without dll injecting iside. Is it possible? Now i use:

g++ `fltk-config --cxxflags` fileName.cpp `fltk-config --ldflags` -o fileName


Thank you
Mike

Albrecht Schlosser

unread,
Apr 16, 2017, 9:22:36 AM4/16/17
to fltkg...@googlegroups.com
On 16.04.2017 12:47 Mich Paw wrote:

> I'd like to compile project, without dll injecting iside. Is it
> possible? Now i use:
>
> |
> g++`fltk-config --cxxflags`fileName.cpp `fltk-config --ldflags`-o fileName

I have only a faint idea what you may mean. Please explain what dll's
you don't want or else.

OTOH, this is what you mean:

g++ `fltk-config --cxxflags` fileName.cpp `fltk-config --ldflags`
-static-libgcc -static-libstdc++ -o fileName

You may also configure FLTK with these LDFLAGS:

LDFLAGS='-static-libgcc -static-libstdc++' ./configure ...

In that case these linker flags will be output by `fltk-config
--ldflags` and you don't need to add them explicitly.

Was this what you meant, and did it help?

Mich Paw

unread,
Apr 16, 2017, 10:25:56 AM4/16/17
to fltk.general, Albrech...@online.de
Thank you, for answer.

My .exe file weight about 1MB, even, that it has less, than 100 lines of code. So I thought, that it add some dlls inside. I'd like to have small exe file, and to run it, I'd like to insert in the same directory dlls, which will be need to run it.

Am I right? I've read, that if I contain dlls inside of exe file, I will not be able, to sell my program (LGPL Licence). I don't know the law, so maybe I'm wrong.

Ian MacArthur

unread,
Apr 16, 2017, 3:05:37 PM4/16/17
to fltkg...@googlegroups.com
On Sun Apr 16 2017 15:25:55, Mich Paw wrote:
>
> My .exe file weight about 1MB, even, that it has less, than 100 lines of code. So I thought, that it add some dlls inside. I'd like to have small exe file, and to run it, I'd like to insert in the same directory dlls, which will be need to run it.
>
> Am I right? I've read, that if I contain dlls inside of exe file, I will not be able, to sell my program (LGPL Licence). I don't know the law, so maybe I'm wrong.

It really sounds like you don’t understand the role of DLL’s as compared to static libraries, here.

In general, DLL’s are never “inside” your executable, though they may be called by your program; the usual interpretation of the LGPL is that it is OK to call external DLL’s, but *maybe* not to link static to them...

This isn’t the forum to discuss this; you’d likely find far better explanations on the web with a little googling.


Which DLL’s are you concerned about?

The FLTK license is a modified LGPL that explicitly permits static linking, so is not usually a concern.


That said, .exe size is probably caused by something else.

Did you strip your executable after building it? If not it probably has a load of symbolic and build information still in it, so you would want to strip it to get rid of that before checking the size.

E.g., for “my_prog.exe” you need to run “strip my_prog.exe” in your msgs shell, then check the size, see if that made it any smaller.






Greg Ercolano

unread,
Apr 16, 2017, 4:26:37 PM4/16/17
to fltkg...@googlegroups.com
On 04/16/17 07:25, Mich Paw wrote:
> Thank you, for answer.
>
> My .exe file weight about 1MB, even, that it has less, than 100 lines of code.
> So I thought, that it add some dlls inside.

In addition to what Ian said..

Try compiling a simple c++ hello world program, e.g.

#include <stdio.h>
int main() { printf("Hello!\n"); return 0; }

..using similar linker flags (minus the FLTK stuff), and see
how big it is.

It's possible your compiler's own C library is being linked
statically into your executable. Also, be sure debugging flags
are turned off, as debugging info can make executables larger.

If you find that's the case, focus on making sure it links
as a dll and not static (i.e. doesn't link with .lib files)

Just be sure to include those dlls with your binary, otherwise
remote users that don't have your compiler installed will get dll
errors.

Even with the Microsoft compiler, I found I had to include some
of the Visual Studio "redistributable DLLs" for the compiler's own
C++ library with my binaries, or some users would get DLL errors
about them.

ed...@tantec.de

unread,
Apr 17, 2017, 4:58:04 AM4/17/17
to Ed
Mich Paw schrieb:
> My .exe file weight about 1MB, even, that it has less, than 100 lines
> of code. So I thought, that it add some dlls inside.

Your program just has much more than 100 lines of code, but you don't
see them. You included libraries and used them, so you added some code
of the libraries to your program, at least a call to dll code. How much
it gets in the end depends of usage and kind of libraries, but a
graphical user interface finally needs a lot of code.

You could try different versions of "hello world" program and change the
kind of output, to get a feeling for "injected code".

#include <stdio.h> => printf("Hello World");

#include <iostream.h> => std::cout << "Hello World" << endl;

And finally the FLTK, which shows a window and needs lots of code for that.

> I'd like to have small exe file

To shrink the exe file a lot, you can strip the symbols by usage of the
linker flag '-s':

g++ -s -o "test.exe" test_cpp.o

This should create a noticiable shorter exe file. But be aware, not to
use '-s' for debugging mode, because this will disable debugging.

Anyway you should take care of the compiler flags for optimization and
debug - to get a short exe you need to optimize and to disable debug.

>, and to run it, I'd like to insert in the same
> directory dlls, which will be need to run it.

I like to static link required libraries. This way the program doesn't
depend on a directory or some kind of installation, but can be started
anywhere.

The FLTK in fact normally is static linked and part of your program, but
you also could link your program to a FLTK dll. This saves space, when
more than one FLTK program is in use, but there also are disadvantages,
e.g. dll must be installed and in search path.

> I've read, that if I contain dlls inside of exe file, I
> will not be able, to sell my program (LGPL Licence). I don't know the
> law, so maybe I'm wrong.

In brief - LGPL means, you can static link it to your program and sell
your program without restrictions, GPL means, you can static link it to
your program and sell your program, but your program now also is GPL and
you need to publish the source code. So you can static link FLTK without
restrictions, but when linking some other library you need to take care
about the licence of the library.
Reply all
Reply to author
Forward
0 new messages