build failure when trying to cross-compile Qt 4.8.

2019-02-25 21:08发布

问题:

I am trying to build a pristine Qt 4.8.3 tarball, and I configured the build with this command:

./configure -opensource -xplatform win32-g++ -device-option CROSS_COMPILE=i686-w64-mingw32-

Following is a result of (re)running make:

$ make
cd src/tools/bootstrap/ && make -f Makefile 
make[1]: Entering directory `/home/wena/src/qt-4.8.3/src/tools/bootstrap'
make[1]: Nothing to be done for `first'.
make[1]: Leaving directory `/home/wena/src/qt-4.8.3/src/tools/bootstrap'
cd src/tools/moc/ && make -f Makefile 
make[1]: Entering directory `/home/wena/src/qt-4.8.3/src/tools/moc'
make[1]: Nothing to be done for `first'.
make[1]: Leaving directory `/home/wena/src/qt-4.8.3/src/tools/moc'
cd src/tools/rcc/ && make -f Makefile 
make[1]: Entering directory `/home/wena/src/qt-4.8.3/src/tools/rcc'
make[1]: Nothing to be done for `first'.
make[1]: Leaving directory `/home/wena/src/qt-4.8.3/src/tools/rcc'
cd src/tools/uic/ && make -f Makefile 
make[1]: Entering directory `/home/wena/src/qt-4.8.3/src/tools/uic'
make[1]: Nothing to be done for `first'.
make[1]: Leaving directory `/home/wena/src/qt-4.8.3/src/tools/uic'
cd src/winmain/ && make -f Makefile 
make[1]: Entering directory `/home/wena/src/qt-4.8.3/src/winmain'
make -f Makefile.Debug all
make[2]: Entering directory `/home/wena/src/qt-4.8.3/src/winmain'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/wena/src/qt-4.8.3/src/winmain'
make -f Makefile.Release all
make[2]: Entering directory `/home/wena/src/qt-4.8.3/src/winmain'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/wena/src/qt-4.8.3/src/winmain'
make[1]: Leaving directory `/home/wena/src/qt-4.8.3/src/winmain'
cd src/corelib/ && make -f Makefile 
make[1]: Entering directory `/home/wena/src/qt-4.8.3/src/corelib'
make -f Makefile.Debug all
make[2]: Entering directory `/home/wena/src/qt-4.8.3/src/corelib'
i686-w64-mingw32-g++ -shared -mthreads -Wl,--out-implib,/home/wena/src/qt-4.8.3/lib/libQtCored4.a -o ../../lib/QtCored4.dll object_script.QtCored.Debug  -L'/home/wena/src/qt-4.8.3/lib' -L'/home/wena/src/qt-4.8.3/lib' -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 .obj/debug-shared/QtCored_resource_res.o 
Creating library file: /home/wena/src/qt-4.8.3/lib/libQtCored4.a
./.obj/debug-shared/qtextcodec.o: In function `setup':
/home/wena/src/qt-4.8.3/src/corelib/codecs/qtextcodec.cpp:771: undefined reference to `QGb18030Codec::QGb18030Codec()'
/home/wena/src/qt-4.8.3/src/corelib/codecs/qtextcodec.cpp:772: undefined reference to `QGbkCodec::QGbkCodec()'
/home/wena/src/qt-4.8.3/src/corelib/codecs/qtextcodec.cpp:773: undefined reference to `QGb2312Codec::QGb2312Codec()'
/home/wena/src/qt-4.8.3/src/corelib/codecs/qtextcodec.cpp:774: undefined reference to `QEucJpCodec::QEucJpCodec()'
/home/wena/src/qt-4.8.3/src/corelib/codecs/qtextcodec.cpp:775: undefined reference to `QJisCodec::QJisCodec()'
/home/wena/src/qt-4.8.3/src/corelib/codecs/qtextcodec.cpp:776: undefined reference to `QSjisCodec::QSjisCodec()'
./.obj/debug-shared/qtextcodec.o: In function `QEucKrCodec':
/home/wena/src/qt-4.8.3/src/corelib/codecs/../../plugins/codecs/kr/qeuckrcodec.h:77: undefined reference to `vtable for QEucKrCodec'
./.obj/debug-shared/qtextcodec.o: In function `QCP949Codec':
/home/wena/src/qt-4.8.3/src/corelib/codecs/../../plugins/codecs/kr/qeuckrcodec.h:91: undefined reference to `vtable for QCP949Codec'
./.obj/debug-shared/qtextcodec.o: In function `QBig5Codec':
/home/wena/src/qt-4.8.3/src/corelib/codecs/../../plugins/codecs/tw/qbig5codec.h:56: undefined reference to `vtable for QBig5Codec'
./.obj/debug-shared/qtextcodec.o: In function `QBig5hkscsCodec':
/home/wena/src/qt-4.8.3/src/corelib/codecs/../../plugins/codecs/tw/qbig5codec.h:70: undefined reference to `vtable for QBig5hkscsCodec'
collect2: ld returned 1 exit status
make[2]: *** [../../lib/QtCored4.dll] Error 1
make[2]: Leaving directory `/home/wena/src/qt-4.8.3/src/corelib'
make[1]: *** [debug-all] Error 2
make[1]: Leaving directory `/home/wena/src/qt-4.8.3/src/corelib'
make: *** [sub-corelib-make_default-ordered] Error 2

I am building on latest Debian 7 (Wheezy).

回答1:

I had the same error when cc-ing 4.7 with -no-iconv.

Came to this hack to src/corelib/codecs/codecs.pri:

win32 {
        !contains(QT_CONFIG,iconv) {
                # no iconv, so we put all plugins in the library
                HEADERS += \
                        ../plugins/codecs/cn/qgb18030codec.h \
                        ../plugins/codecs/jp/qeucjpcodec.h \
                        ../plugins/codecs/jp/qjiscodec.h \
                        ../plugins/codecs/jp/qsjiscodec.h \ 
                        ../plugins/codecs/kr/qeuckrcodec.h \
                        ../plugins/codecs/tw/qbig5codec.h \
                        ../plugins/codecs/jp/qfontjpcodec.h
                SOURCES += \
                        ../plugins/codecs/cn/qgb18030codec.cpp \
                        ../plugins/codecs/jp/qjpunicode.cpp \
                        ../plugins/codecs/jp/qeucjpcodec.cpp \
                        ../plugins/codecs/jp/qjiscodec.cpp \
                        ../plugins/codecs/jp/qsjiscodec.cpp \ 
                        ../plugins/codecs/kr/qeuckrcodec.cpp \
                        ../plugins/codecs/tw/qbig5codec.cpp \
                        ../plugins/codecs/jp/qfontjpcodec.cpp
        }
}

There were other errors and hacks, but it looks like they're gone in 4.8.3.



回答2:

You are missing the libiconv library used by the text codec plugins. Someone with the same problem here.



回答3:

To avoid this error:

In file included from main.cpp:42:0: dialog.h:65:5: error: ‘QSharedMemory’ does not name a type

Looks like mxe uses ./configure -nomake examples ... (another option is what vlc uses, which is to just do make sub-src instead of global make--though you can't use make install with this method since it still tries to build the examples). Seems like a bug in qt to me...or maybe using the locally built qmake would help, didn't try that...

See also How do I configure Qt for cross-compilation from Linux to Windows target?