0

Currently I just created a small software in C and GTK + -3, everything is working perfectly on my machine but when I test the software on another laptop has several errors that refer to DLL libraries. On a first try the libglib-2.0-0.dll library was missing, then libwinpthread-1.dll, libintl-8.dll, libiconv-2.dll, library and whenever I add to the missing library a new missing library appears.

I'm wondering if there is any way to include the libraries in the executable at compile time?

I am using mingw64.exe for the build and this is my current makefile:

# Tools
CC=x86_64-w64-mingw32-gcc
LD=x86_64-w64-mingw32-gcc
CFLAGS=--std=c99 --pedantic -Wall -W -Wmissing-prototypes -g
LDFLAGS=
SGTKFLAGS=`pkg-config --cflags gtk+-3.0`
EGTKFLAGS=`pkg-config --libs gtk+-3.0`

# Files
EXEC=text_decoration
HEADERS=model.h view.h controller.h
MODULES=model.c view.c controller.c text_decoration.c
OBJECTS=model.o view.o controller.o text_decoration.o

# Commands
RM=rm
RMFLAGS=-f

# Start point
all:$(EXEC)

# Règle pour la génération de l'exécutable
text_decoration: $(MODULES) $(HEADERS)
    $(CC) $(SGTKFLAGS) -g -o $(EXEC) $(MODULES) $(HEADERS) $(EGTKFLAGS)

clean:
    $(RM) $(RMFLAGS) $(EXEC).exe

For a moment I thought it was due to compiling with the make command, when I try to use command nmake, I had the following error:

C:\msys64\home\Mooo\a>nmake

Microsoft (R) Program Maintenance Utility Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

        x86_64-w64-mingw32-gcc `pkg-config --cflags gtk+-3.0` -g -o text_decoration model.c view.c controller.c text_decoration.c model.h view.h controller.h `pkg-config --libs gtk+-3.0`
x86_64-w64-mingw32-gcc.EXE: error: `pkg-config: No such file or directory
x86_64-w64-mingw32-gcc.EXE: error: gtk+-3.0`: No such file or directory
x86_64-w64-mingw32-gcc.EXE: error: `pkg-config: No such file or directory
x86_64-w64-mingw32-gcc.EXE: error: gtk+-3.0`: No such file or directory
x86_64-w64-mingw32-gcc.EXE: error: unrecognized command line option '--cflags'
x86_64-w64-mingw32-gcc.EXE: error: unrecognized command line option '--libs'
NMAKE : fatal error U1077: 'C:\msys64\mingw64\bin\x86_64-w64-mingw32-gcc.EXE' : return code '0x1'
Stop.
  • Backticks for command substitution only work in Bourne shells; nmake runs everything through the Windows command prompt, which is not a Bourne shell. You'll have to see if either nmake or cmd.exe provide an equivalent syntax. If you are also using GNU make, it is likely also using the Windows command prompt, but with GNU make the syntax is `$(shell command arguments...)`. – andlabs Feb 16 '18 at 23:32
  • Even when you get it building correctly, you still need to package the redistributable DLL's with your executable. First you have to identify all your dependencies. – jwdonahue Feb 17 '18 at 01:42
  • An easy way is to build a `PIC` / `static` / `32bit` application. Then everything will be contained in the application such that (assuming all the needed peripherals are available) can be run on any machine that uses the same type of CPU – user3629249 Feb 19 '18 at 01:32
  • suggest adding a couple more flags to the `cflags` macro. `-Wextra` `Wconversion`. Note this `-W` turns OFF all the warnings – user3629249 Feb 19 '18 at 01:37

1 Answers1

0

I'm wondering if there is any way to include the libraries in the executable at compile time?

This would mean statically compiling the whole GTK+ stack to produce static libraries instead of shared libraries. I think that's not really supported nor desirable.

Instead if you're using MSYS2 (which is the preferred way to install GTK+ 3), you can create a package for it, and then install that package and its dependencies (your own, as well as GTK+ dependencies) in an specific location. The result of that installation is what you can redistribute and should be independent.

Please read that blog article about GTK+ application redistristribution on Windows. It takes the example of gedit that has all this.

liberforce
  • 11,189
  • 37
  • 48