Search code examples
c++mingwwxwidgetsstatic-librariespremake

Reference errors when linking wxWidgets statically


I'm using this Premake4 script for wxWidgets in my build script:

wx_config {Unicode="yes", Version="2.9", Libs="core,aui,media,html", WindowsCompiler="gcc", Static="yes"}

But CodeBlocks respectively MinGW outputs many errors:

wx\lib\gcc_lib/libwxbase29u.a(baselib_filename.o):filename.cpp:(.text+0x5371): undefined reference to `CoCreateInstance@20'
wx\lib\gcc_lib/libwxbase29u.a(baselib_filename.o):filename.cpp:(.text+0x5390): undefined reference to `IID_IPersistFile'
wx\lib\gcc_lib/libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+0x7cc9): undefined reference to `wxEVT_POWER_SUSPEND_CANCEL'
wx\lib\gcc_lib/libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+0x7cf9): undefined reference to `vtable for wxPowerEvent'
wx\lib\gcc_lib/libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+0x7d55): undefined reference to `wxEVT_POWER_SUSPENDED'
wx\lib\gcc_lib/libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+0x7d61): undefined reference to `wxEVT_POWER_SUSPENDING'
wx\lib\gcc_lib/libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+0x7d6d): undefined reference to `wxEVT_POWER_RESUME'
wx\lib\gcc_lib/libwxmsw29u_core.a(corelib_window.o):window.cpp:(.text+0x7f18): undefined reference to `vtable for wxPowerEvent'
...

You can see all linker errors here: http://pastebin.com/UGSRg4DX

Someone mentioned in a wxWidgets bug report(link lost) that the library order is causing this problem. But he didn't say which library has to be put first.


Solution

  • This looks like exactly the same problem as this one. I.e. you need to put the libraries in your premake script in the right order: aui,media,html,core (the important thing is that "core" is the last one). Also, I don't know if it's appended implicitly perhaps but normally you'd also need "base" at the very end.