PDA

View Full Version : cross compiling with static libraries



janK
3rd July 2012, 20:49
Hello

I have an application developed under Linux. It is running under W7 (mingw/Qt), but in order to distribute it to some
interested parties I want to make a distribution with (most of the) libs statically linked.
In order to do so, I installed under fedora-17 the mingw64 cross compilation set, including the static libs for Qt.
When building a non-statically bound version, it compiles completely to an executable.
When adding the QMAKE_LFLAGS += -static to the ".pro" file, compilation starts complaining about
some references from the libs not being resolved. Most likely they are windows references, but I have no clue
what libs to add.
This is the result of the link phase

x86_64-w64-mingw32-g++ -static -Wl,-s -Wl,-subsystem,console -mthreads -o release/spectrum-viewer.exe object_script.spectrum-viewer.Release -L'/usr/x86_64-w64-mingw32/sys-root/mingw/lib' /home/jan/cross-compiling/dll_64/libfftw3-3.lib /home/jan/cross-compiling/qwt-5.2.2/lib/libqwt.a -L c:\mingw\lib -lole32 -lwinmm -lstdc++ -lusb-1.0 -lQtGui4 -lQtCore4
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libQtGui4.a(qapplication.o):(.text+0x1824): undefined reference to `__imp_CoCreateGuid'
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libQtGui4.a(qapplication.o):(.text+0x1849): undefined reference to `__imp_StringFromGUID2'
/usr/lib64/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld: /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libQtGui4.a(qapplication.o): bad reloc address 0x0 in section `.data'
/usr/lib64/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld: final link failed: Invalid operation

Note that when I add " -lole32 -lwinmm" at the end of the link line, these specific references seem to be resolved, however, some other appear.

Any help is greatly appreciated

jan

janK
4th July 2012, 12:38
OK,
I found some of the missing symbols (with help from the mingw64-public) mailing list. However, it seems strange that
when using the static versions of the Qt libs (from the packages in fedora-17) there are further libraries needed that are not specified.
It seems I have to add "-lole32 -luuid -lgdi32" to the link command line in the generated makefile

I have still some symbols left that are undefined, and I really have no clue where to find these in the Mingw64 cross environment

make -f Makefile.Release
make[1]: Entering directory `/home/jan/cross-compiling/jsdr-3.04/spectrum-viewer'
x86_64-w64-mingw32-g++ -static -Wl,-s -Wl,-subsystem,console -mthreads -o release/spectrum-viewer.exe object_script.spectrum-viewer.Release -L'/usr/x86_64-w64-mingw32/sys-root/mingw/lib' /home/jan/cross-compiling/qwt-5.2.2/lib/libqwt.a /home/jan/cross-compiling/dll_64/libfftw3-3.lib -lole32 -lwinmm -lstdc++ -lusb-1.0 -lQtGui4 -lQtCore4 -lole32 -lgdi32 -luuid
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libQtGui4.a(qaccessible_win.o):(.text+0x1c56): undefined reference to `__imp_SysAllocStringLen'
.....
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libQtGui4.a(qaccessible_win.o):(.text+0x2cda): more undefined references to `__imp_SysAllocStringLen' follow
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libQtGui4.a(qaccessible_win.o):(.text+0x3970): undefined reference to `__imp_VariantInit'
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libQtGui4.a(qaccessible_win.o):(.text+0x41d8): undefined reference to `__imp_PlaySoundW'
/usr/lib64/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld: /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libQtGui4.a(qaccessible_win.o): bad reloc address 0x0 in section `.data'
/usr/lib64/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status

If anyone could give a pointer how to locate the libraries for missing symbols in the mingw64 cross compilation environment, it would be a great help

best
jan

high_flyer
4th July 2012, 12:50
A quick google produces:
SysAllocStringLen -> oleaut32.lib
PlaySoundW -> Winmm.lib
VariantInit -> oleaut32.lib

janK
4th July 2012, 13:04
Yes, true, but that does not solve my problem since I need to find the symbols in the libs used by mingw64 in a cross compilation environment,
So, the question could be restated as: what mingw64 libs correspond to these libs

Thanks anyway

best
jan

high_flyer
4th July 2012, 13:17
This is a question for MinGW forum, you probably will get more help there.

janK
4th July 2012, 13:45
Solved!!
It was my mistake, having not set the right option to CONFIG in the
".pro" file.

best
jan

high_flyer
4th July 2012, 13:58
Will be nice if you share exactly what the mistake was and what the fix is, so other having similar problems can be helped by it.

janK
4th July 2012, 15:15
When searching how to compile with static libs, I found one mailer who added
QMAKE_LFLAGS= -static
which I did, and which gave problems as described.
Another page on the web gave a more precise detailing of what to do, which
is essentially set
CONFIG += static

which does the trick perfectly (just look for Tutorial for cross compiling).

So, I compiled my sdr package on Fedora 17, using mingw64 cross compiler tools and
indeed the resulting software works on windows.
Still have to configure one or two packages for the whole functionality, but my program works.

Thankx for the interest
jan