#118 wxWidgets link order breaks build

open
nobody
None
5
2011-11-16
2011-11-16
Nickolay Cherney
No

It looks like cmake\modules\wxwidgets.cmake contains command
find_package(wxWidgets COMPONENTS core base QUIET)
which results in wrong link order (al least for ld/MinGW/MSWin), That's because the given order of the wxWidgets libraries (i.e. core base) goes directly to the internals of cmake\modules\FindwxWidgets.cmake, where it is converted to linker's option string (showing archives), which is, in turn, fed to ld from command string, that results in unresolved symbols (from wx core lib).
By the way, the comments in FindwxWidgets.cmake suggest different order (i.e. base core) which results in correct build (see attachment).

Built PLplot with command:
cmake -G "MinGW Makefiles" -DwxWidgets_ROOT_DIR=c:/wxWidgets -DwxWidgets_LIB_DIR=c:/wxWidgets/lib/gcc_lib -DCMAKE_INSTALL_PREFIX=c:/PLplot -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_COLOR_MAKEFILE=OFF ..

Other info:
- MinGW (get-inst-20110802);
- cmake 2.8.6;
- wxWidgets 2.9.2, built in directory c:\wxWidgets (for cmake's WIN32_FIND_STYLE) with command: cd build/msw & mingw32-make.exe -f makefile.gcc BUILD=release MONOLITHIC=0 UNICODE=1 SHARED=0

Discussion

  • Andrew Smart
    Andrew Smart
    2012-09-14

    I've observed the wrong order of wx static libs being linked to as well. For me trunk of wxWidgets BUILD=release MONOLITHIC=0 UNICODE=1 SHARED=0

    Though for me static build of plPlot linked fine. As a side note my apps using static wxWidgets+static plPlot crash at runtime because apparently both plPlot and wxWidgets can't be statically linked to; one or the other must not be because of things like wxGetApp()). Relevant plPlot cmake params: BUILD_SHARED_LIBS=0,ENABLE_DYNDRIVERS=0

    Current build of plPlot doesn't link as observed due to the way cmake orders the static wx libraries when linking. Relevant plPlot params in this case: BUILD_SHARED_LIBS=1,ENABLE_DYNDRIVERS=1

    Here is output of Mingw make:
    [ 33%] Built target plplotd
    [ 33%] Built target plplotcxxd
    Linking CXX shared library ..\..\dll\libplplotwxwidgetsd.dll
    Creating library file: ..\..\dll\libplplotwxwidgetsd.dll.a
    C:\wxWidgets\lib\gcc_lib\libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+
    0xcab5): undefined reference to `wxEVT_POWER_SUSPENDING'
    C:\wxWidgets\lib\gcc_lib\libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+
    0xcadd): undefined reference to `vtable for wxPowerEvent'
    C:\wxWidgets\lib\gcc_lib\libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+
    0xcb39): undefined reference to `wxEVT_POWER_SUSPENDED'
    C:\wxWidgets\lib\gcc_lib\libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+
    0xcb45): undefined reference to `wxEVT_POWER_RESUME'
    C:\wxWidgets\lib\gcc_lib\libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+
    0xcb51): undefined reference to `wxEVT_POWER_SUSPEND_CANCEL'
    C:\wxWidgets\lib\gcc_lib\libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+
    0xcda6): undefined reference to `vtable for wxPowerEvent'
    C:\wxWidgets\lib\gcc_lib\libwxmsw29u_core.a(corelib_geometry.o):geometry.cpp:(.t
    ext+0x37b): undefined reference to `wxDataOutputStream::Write32(unsigned int)'
    ...

    The above is shown when wxWidgets static libs are linked in wrong order (I often inadvertently replicated this in non-plPlot applications, it is hard to get the link order right). Thank you for the patch Nickolay, I'll see if it works for me.

     
  • Andrew Smart
    Andrew Smart
    2012-09-14

    Order in CMakeCache.txt:
    plplotwxwidgetsd_LIB_DEPENDS:STATIC=general;plplotcxxd;general;C:/wxWidgets/lib/gcc_lib/libwxbase29u.a;general;C:/wxWidgets/lib/gcc_lib/libwxmsw29u_core.a;general;C:/wxWidgets/lib/gcc_lib/libwxpng.a;general;C:/wxWidgets/lib/gcc_lib/libwxtiff.a;general;C:/wxWidgets/lib/gcc_lib/libwxjpeg.a;general;C:/wxWidgets/lib/gcc_lib/libwxzlib.a;general;C:/wxWidgets/lib/gcc_lib/libwxregexu.a;general;C:/wxWidgets/lib/gcc_lib/libwxexpat.a;general;winmm;general;comctl32;general;rpcrt4;general;wsock32;general;C:/plplot/deps/agg-2.4/lib/libagg.a;general;C:/plplot/deps/freetype-2.4.10/objs/libfreetype.a;

    I think it should be (expat,regex,msw_core,jpeg,png,tiff,zlib,base):
    plplotwxwidgetsd_LIB_DEPENDS:STATIC=general;plplotcxxd;general;C:/wxWidgets/lib/gcc_lib/libwxexpat.a;general;C:/wxWidgets/lib/gcc_lib/libwxregexu.a;general;C:/wxWidgets/lib/gcc_lib/libwxmsw29u_core.a;general;C:/wxWidgets/lib/gcc_lib/libwxjpeg.a;general;C:/wxWidgets/lib/gcc_lib/libwxpng.a;general;C:/wxWidgets/lib/gcc_lib/libwxtiff.a;general;C:/wxWidgets/lib/gcc_lib/libwxzlib.a;general;C:/wxWidgets/lib/gcc_lib/libwxbase29u.a;general;winmm;general;comctl32;general;rpcrt4;general;wsock32;general;C:/plplot/deps/agg-2.4/lib/libagg.a;general;C:/plplot/deps/freetype-2.4.10/objs/libfreetype.a;

     
  • Andrew Smart
    Andrew Smart
    2012-09-14

    Ok confirmed, your patch fixes my problem Mr. Nickolay Cherney. Thank you very much. Nothing else was needed.