Static linking

From WxWiki
Jump to navigation Jump to search

If under Windows (Visual Studio) you want to link wxWidgets statically (to avoid requiring the Microsoft Visual C++ Runtime in order to run the executable on other PCs) and you get this error message:

error LNK2019: unresolved external symbol "public: void __thiscall wxStringData::Free(void)" (?Free@wxStringData@@QAEXXZ) referenced in function "public: void __thiscall wxStringData::Unlock(void)" (?Unlock@wxStringData@@QAEXXZ)

or similar, try the following:

Open wxWidgets\build\msw\wx.dsw, select "Unicode Release", shift-click to select all the ~20 projects, right click and select project properties, and under C++ --> Code Generation, change Runtime Library to "Multi-threaded (/MT)". For "Unicode Debug" you should use "Multi-threaded Debug" (/MTd).

It also might be necessary to edit build/msw/config.vc to contain

RUNTIME_LIBS = dynamic 

If you compile your program with the same settings way you can statically link to the wxWidgets libraries in your own project and the exe will work on other PCs without having to install the MSVC redistributable runtime.