Reputation: 1
I may be fundamentally misunderstanding the "-static" option for MinGW g++.exe/ld.exe, but I aim to build my project with the necessary libraries included as static rather than dynamic so that I can ship my executable (.exe) without numerous dlls.
My versions are:
gcc version 4.6.2 (GCC)
GNU ld (GNU Binutils) 2.22
I've searched all around for the last five hours (including https://sourceware.org/binutils/docs/ld/Options.html#Options & http://www.mingw.org/ and stackoverflow), and can't seem to sort this out (yet I've done similar builds in Visual C++. I'm pretty new to MinGW, and don't have the makefile syntax down cold yet. Sorry.)
Here's my makefile:
#Makefile: main.cpp
CC = g++
GCR = glib-compile-resources
GCR_SRC_FLAGS = --generate-source
GCR_HDR_FLAGS = --generate-header
LIBPATH = -L C:/MinGW/lib -L C:/MinGW/GTK3/lib
LIBS = -lgdi32 -lkernel32 -luser32 -lws2_32 -lgtk-3.dll -lgdk-3.dll
CFLAGS = -Wall -mwindows -Wl,-static
#check for invalid symbols: https://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html#id-1.6.3.3.3
CFLAGS += -DGTK_DISABLE_SINGLE_INCLUDES
#disable deprecated symbols
CFLAGS += -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
#main: main.o theme.o theme.gresource.xml $(shell $(GCR) --generate-dependencies theme.gresource.xml)
# $(GCR) $(GCR_SRC_FLAGS) theme.gresource.xml
# $(GCR) $(GCR_HDR_FLAGS) theme.gresource.xml
# -Wl,-whole-archive -Wl,-no-whole-archive
main: main.o theme.o theme.gresource
$(CC) $(CFLAGS) $(LIBPATH) main.o theme.o -o main $(LIBS) `pkg-config gio-windows-3.0` `pkg-config gtk+-3.0 --cflags --libs` `pkg-config gdk-3.0 --cflags --libs`
main.o: main.cpp main.h
$(CC) $(CFLAGS) $(LIBPATH) -c main.cpp -o main.o $(LIBS) `pkg-config gio-windows-3.0` `pkg-config gtk+-3.0 --cflags --libs` `pkg-config gdk-3.0 --cflags --libs`
theme.o: theme.c
$(CC) $(CFLAGS) $(LIBPATH) -c theme.c -o theme.o $(LIBS) `pkg-config gio-windows-3.0` `pkg-config gtk+-3.0 --cflags --libs` `pkg-config gdk-3.0 --cflags --libs`
theme.gresource: theme.gresource.xml $(shell $(GCR) --generate-dependencies theme.gresource.xml)
$(GCR) $(GCR_SRC_FLAGS) theme.gresource.xml
$(GCR) $(GCR_HDR_FLAGS) theme.gresource.xml
clean:
rm -f *.o main
If I remove "-Wl,-static" from the "CFLAGS" variable, the code builds and executes fine. But with "-Wl,-static" included, I get the following errors:
$ make
g++ -Wall -mwindows -Wl,-static -DGTK_DISABLE_SINGLE_INCLUDES -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -L C:/MinGW/lib -L C:/MinGW/GTK3/lib -c main.cpp
-o main.o -lgdi32 -lkernel32 -luser32 -lws2_32 -lgtk-3.dll -lgdk-3.dll `pkg-config gio-windows-3.0` `pkg-config gtk+-3.0 --cflags --libs` `pkg-config gdk-3.0 -
-cflags --libs`
g++ -Wall -mwindows -Wl,-static -DGTK_DISABLE_SINGLE_INCLUDES -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -L C:/MinGW/lib -L C:/MinGW/GTK3/lib -c theme.c
-o theme.o -lgdi32 -lkernel32 -luser32 -lws2_32 -lgtk-3.dll -lgdk-3.dll `pkg-config gio-windows-3.0` `pkg-config gtk+-3.0 --cflags --libs` `pkg-config gdk-3.0 -
-cflags --libs`
g++ -Wall -mwindows -Wl,-static -DGTK_DISABLE_SINGLE_INCLUDES -DGDK_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -L C:/MinGW/lib -L C:/MinGW/GTK3/lib main.o them
e.o -o main -lgdi32 -lkernel32 -luser32 -lws2_32 -lgtk-3.dll -lgdk-3.dll `pkg-config gio-windows-3.0` `pkg-config gtk+-3.0 --cflags --libs` `pkg-config gdk-3.0
--cflags --libs`
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lgtk-3
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lgdk-3
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lfreetype
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lcairo-gobject
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lgdk-3
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lfreetype
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lcairo-gobject
collect2: ld returned 1 exit status
make: *** [main] Error 1
I'm not convinced this mean much, but as a test I added " -lgtk-3.dll -lgdk-3.dll" to my "LIBS" variable, and when I do so (with the ".dll" suffix), they do not trigger errors. If I omit ".dll", I get additional instances of the errors listed along with the others, i.e.:
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lgtk-3
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lgdk-3
These two libraries add as a test exist in my GTK/lib directory as: libgtk-3.dll.a and libgkd-3.dll.a
Am I misunderstanding something crucial, or using incorrect syntax? Both? Any thoughts are much appreciated. Thanks!
Upvotes: 0
Views: 1940
Reputation: 524
When you want to do static linking, you need static version of these libraries.
Here, you need the static version of gtk-3, gdk-3, freetype, and so on.
Usually they are called libgtk-3.a
, libgdk-3.a
, ...
Upvotes: 1