Search code examples
visual-studiovisual-c++static-librarieswxwidgetsupgrade

VC++ specify library order - error LNK2005: already defined


I am upgrading an entire Visual Studio solution from wxWidgets-2.6.4 (A) to wxWidgets-3.0.2 (B). There is a problem because some projects make use of wxhttpengine-2.0 (Z), which does not work with versions of wxWidgets newer than 2.6.x. To simplify the questions, I have labeled the 3 static libraries with letters A, B and Z. So, my solution contains A and Z, Z contains parts of A, but I want to use B instead of A while maintaining Z, in order to simplify the code of my solution. The problem is that simply doing that causes an error - LNK2005: already defined in httpengine.lib - for wxWidgets.3.0.2 static libraries. Conflicting symbols from A and B are discovered by the linker because Z is built on top of A.

The general question: How can I upgrade from A to B the projects that contain Z?

The specific question: Is it possible to specify in Visual Studio that I want to link with B first and then with Z?

Here is a sample error:

Error 1 error LNK2005: "public: class wxSize __thiscall wxWindowBase::GetBestSize(void)const " (?GetBestSize@wxWindowBase@@QBE?AVwxSize@@XZ) already defined in httpengined.lib(proxysettingsdlg.obj) PATH\wxmsw30ud_core.lib(hidden_filename.obj)


Solution

  • You can't statically link with two different versions of wxWidgets. The best you could do would be to link dynamically with at least one and, to avoid confusion, probably better with both, of them.

    However I'd actually looking into why exactly doesn't wxhtttpengine work with wxWidgets 3.0. It shouldn't be hard to fix this and using a single version of the library is obviously much simpler.