Problem description:
I have a Visual Studio 2012 C++ project which uses wxWidgets. It compiles and links perfectly.
For reasons we won't go into, I now need to make this work with Visual Studio 2015.
Having twiddled the settings and got all the code to compile, it now refuses to link because all the libraries it uses are compiled for VS 2012. OK...
I replaced all the libraries with ones compiled for VS 2015. Everything works again... except wxWidgets.
I have now spent multiple days fruitlessly trying to force wxWidgets to work. It just won't do it.
Here's what I've done so far:
Looking at the instructions at https://github.com/wxWidgets/wxWidgets/releases/, it appears I'm supposed to download and unpack two files:
wxWidgets-3.1.1-headers.7z (which contains an include folder)
wxMSW-3.1.1_vc140_Dev.7z (which contains a lib folder).
I deleted the old wxWidgets stuff, and unpacked these two new zips.
Hundreds of preprocessor errors saying it can't find some include file. It looks like the old directory structure had ...\lib\vc_lib\... rather than ..\lib\vc140_dll\..., so I tried renaming the folder. Now everything compiles successfully.
Next the linker complains that it can't find wxbmsw28ud_core.lib — which makes sense, considering I just deleted it. I changed all the filenames to be *31 rather than *28, and no more file-not-found errors.
Now I have hundreds of LNK2001 errors. For example:
Error LNK2001 unresolved external symbol "protected: static struct wxEventTable const wxDialogBase::sm_eventTable" (?sm_eventTable#wxDialogBase##1UwxEventTable##B)
I don't understand this though. If I run DumpBin.exe against wxmsw31ud_core.lib, it dumps out several megabytes of text, including:
5146A2 __imp_?sm_eventTable#wxDialogBase##1UwxEventTable##B
and also
29C0 __imp_?sm_eventTable#wxDialogBase##1UwxEventTable##B
and also
Version : 0
Machine : 14C (x86)
TimeDateStamp: 5A8A0543 Sun Feb 18 22:59:15 2018
SizeOfData : 00000049
DLL name : wxmsw311ud_core_vc140.dll
Symbol name : ?sm_eventTable#wxDialogBase##1UwxEventTable##B (protected: static struct wxEventTable const wxDialogBase::sm_eventTable)
Type : data
Name type : name
Hint : 14306
Name : ?sm_eventTable#wxDialogBase##1UwxEventTable##B
In other words, the exact symbol that VS says it can't find!
So if the symbol is in the .lib file and I can see it there, why is VS complaining that it's not in the .lib file?
Just to be 100% certain, I made a table of every single symbol that VS claims it can't find and which .lib file it's actually in:
LNK2001 ?sm_eventTable#wxDialogBase##1UwxEventTable##B wxmsw31ud_core.lib
LNK2001 ?wxTheAssertHandler##3P6AXABVwxString##H000#ZA wxbase31ud.lib
LNK2001 ?wxTrapInAssert##3_NA wxbase31ud.lib
LNK2001 ?wxConvLibcPtr##3PAVwxMBConv##A wxbase31ud.lib
LNK2001 ?wxEmptyString##3PB_WB wxbase31ud.lib
LNK2001 ?npos#wxString##2IB wxbase31ud.lib
LNK2001 ?sm_first#wxClassInfo##0PAV1#A wxbase31ud.lib
LNK2001 ?wxNullBitmap##3VwxBitmap##A wxmsw31ud_core.lib
LNK2001 ?wxNullIcon##3VwxIcon##A wxmsw31ud_core.lib
LNK2001 ?wxDefaultSize##3VwxSize##B wxmsw31ud_core.lib
LNK2001 ?wxDefaultPosition##3VwxPoint##B wxmsw31ud_core.lib
LNK2001 ?wxEVT_NULL##3HB wxbase31ud.lib
LNK2001 ?wxEVT_BUTTON##3V?$wxEventTypeTag#VwxCommandEvent####B wxmsw31ud_core.lib
LNK2001 ?wxDefaultValidator##3VwxValidator##B wxmsw31ud_core.lib
LNK2001 ?wxButtonNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?ms_classInfo#wxDialog##2VwxClassInfo##A wxmsw31ud_core.lib
LNK2001 ?wxStaticTextNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxListCtrlNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxConvUTF8Ptr##3PAVwxMBConvStrictUTF8##A wxbase31ud.lib
LNK2001 ?ms_appInitFn#wxAppConsoleBase##1P6APAVwxAppConsole##XZA wxbase31ud.lib
LNK2001 ?ms_appInstance#wxAppConsoleBase##1PAVwxAppConsole##A wxbase31ud.lib
LNK2001 ?ms_idMainThread#wxThread##0KA wxbase31ud.lib
LNK2001 ?wxEVT_CLOSE_WINDOW##3V?$wxEventTypeTag#VwxCloseEvent####B wxmsw31ud_core.lib
LNK2001 ?wxEVT_SIZING##3V?$wxEventTypeTag#VwxSizeEvent####B wxmsw31ud_core.lib
LNK2001 ?wxEVT_COMMAND_ENTER##3V?$wxEventTypeTag#VwxCommandEvent####B wxmsw31ud_core.lib
LNK2001 ?wxTextCtrlNameStr##3QBDB wxmsw31ud_core.lib
LNK2001 ?wxGaugeNameStr##3QBDB wxmsw31ud_core.lib
LNK1120 28 unresolved externals
As you can see, every single symbol is listed in either wxmsw31ud_core.lib or wxbase31ud.lib, which are both configured in the project (along with several additional wxWidgets libraries as well).
I don't understand what the problem is. I don't get why it's complaining at me. But I need to make this work. Any suggestions?
Mixing compiled files from different VS versions will lead to errors ("not found" or "incompatible") in the linking stage. Also, mixing 32/64 versions will fail.
Delete (or move to a different dir) all of [old] wxWidgets stuff, specially the generated dirs and objects during a previous wxWidgets building.
Download current wxWidgets sources from official page, or the Windows installer.
Build using the proper VS solution. Taken from wxdir\docs\msw\install.txt:
Ready to use project files are provided for VC++ versions 7, 8, 9, 10,
11, 12, 14 and 15 (also known as MSVS 2003, 2005, 2008, 2010, 2012,
2013, 2015 and 2017 respectively).
Simply open wx_vcN.sln (for N=7, 8, 9, 10, 11, 12, 14, or 15) file,
select the appropriate configuration (Debug or Release, static or DLL)
and build the solution. Notice that when building a DLL configuration,
you may need to perform the build several times because the projects
are not always built in the correct order, and this may result in link
errors. Simply do the build again, up to 3 times, to fix this.
So, simply open wx_vc14.sln and build your solution. It seems you want static library, so wx gets embedded into your app; if not, select the DLL solution.
Notice that in that wxWidgets download page you can directly get the headers and the static ("Development") or dynamic ("Release DLL") already compiled files, so as to avoid wxWidgets compilation itself.
Your link error is due to the linker looking for the function in a static library, while you're linking with DLL import libraries. IOW when you write
In other words, the exact symbol that VS says it can't find!
it is just wrong because there is clearly a difference: one symbol has the __imp__ prefix and the other one doesn't.
Either rebuild your application with WXUSINDLL defined or link with static wx libraries.
And, honestly, all of us make mistakes and it may happen that you spend hours or even days on something that can be solved in minutes, but blaming your tools really doesn't help when the problem is not with them.
On top of a great help from Vadim and Ripi2, I think you are also trying to upgrade wxWidgets from version 2.8 to 3.0. This is in itself a huge task and you should consider do one properly then the other.
I'd start with the building 2.8 source statically with the compiler at hand and then try to ujpgrade the version of wxWidgets very carefully.
Thank you.
I eventually gave up and attempted to build wxWidgets from source.
It took many, many attempts, but eventually I was able to compile wxWidgets in such a way that my application now builds successfully. It seems you have to check that all the hundreds of thousands of compilation settings in VS are identical to the target application. No, it doesn't seem to be possible to automate that.
(Having said all that, compared to how nightmarishly difficult it usually is to build anything C-related from source, this was comparatively easy...)
I would like to integrate Lua into my current C++ application I build with VisualStudio 2015 (x64 mode).
I grabbed a simple Lua wrapper from here, and the Lua binaries for windows x64 from here (the lua-5.1.5_Win32_dll14_lib.zip one).
Next, I added the include and library path to the project preferences. Works so far in the IDE. However, when I try to compile the code it throws 24 errors (like these first two):
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_close" referenced in function ""public: __cdecl LuaScript::~LuaScript(void)" (??1LuaScript##QEAA#XZ)".
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_gettop" referenced in function ""public: void __cdecl LuaScript::clean(void)" (?clean#LuaScript##QEAAXXZ)".
which tells me next to nothing. Seems that the linker is unable to find the library but the includes are working and the path to library is set, too. Any suggestions what I might have missed or should look into? Any hint would be appreciated!
For a research project, I'm writing a C++ add-on to a scientific computing language. Unfortunately the library that allows users to do this is not kept very well up-to-date.
I started the project in XCode, where it built fine. Later I had to move to a PC, so I migrated the code to Visual Studio 2015. Since doing this, I haven't been able to build due to the following errors:
LNK2001 : unresolved external symbol _sprintf
LNK2019 : unresolved external symbol _sscanf referenced in function _GetDDouble
LNK2019 : unresolved external symbol _sprintf referenced in function _CheckRunningInMainThread
An attempted fix was to add the header #define _CRT_SECURE_NO_WARNINGS. However, this a) fixed no errors and b) added the warning C4005 : '_CRT_SECURE_NO_WARNINGS': macro redefinition. I assume the library already defined this macro, anticipating this problem. Regardless, it didn't solve the problem.
How should I proceed?
Add the following library to the linker input files:
legacy_stdio_definitions.lib
VS 2015 now uses inline definitions that call internal functions for many of the stdio.h functions. If an object file (or library member) depends on one of those functions, then the legacy_stdio_definitions.lib provides an externally linkable version of the function that can be linked to.
Your other option is to recompile the unit that depends on those functions with VS 2015 (this is probably the preferred option).
I got this error compiling cycling max plugins against version 5 max sdk (pure c api). The legacy library fix didn't work for me (it should have, and if anyone had any idea why it mightn't I'd be curious), but I defined _NO_CRT_STDIO_INLINE before stdio was loaded and that did do the trick.
I recently encountered this and was able to add User32.lib to Linker > Input > Additional Dependencies.
You could also include #pragma comment (lib, "User32.lib") in your code.
I get the following error trying to build the "hello world" example from ZeroMQ.
Error LNK2019: unresolved external symbol __imp__zmq_msg_init
referenced in function _wmain
I've added the library and header paths to the project (BTW how do I add them to the default settings?) and I've tried adding "libzmq-v100-mt.lib" (and "libzmq-v100-mt-gd.lib") to the linker additional inputs property. This didn't help.
Any other ideas?
The ZeroMQ headers (zmq.h in particular), by default, appear only to support dynamic linking on win32.
Try #define-ing ZMQ_EXPORT. That way, it won't see the __declspec(dllimport) declaration and won't expect to link against a .dll.
Link errors like this sometimes occur when compiling C++ using Microsoft Visual C++ 6.0:
error LNK2001: unresolved external symbol __imp__close
error LNK2001: unresolved external symbol __imp__read
error LNK2001: unresolved external symbol __imp__lseek
error LNK2001: unresolved external symbol __imp__open
My fix, which I found after searching fruitlessly using Google for a long time, is this:
Do NOT disable language extensions. In the Project Settings dialog, in the C/C++ tab, make sure that the 'Disable language extensions' checkbox is not checked.
The functions close, read, lseek, open, etc., are not standard parts of the C library and the declarations are skipped by conditional compilation using #if !__STDC__ in <io.h>. This happens if you disable language extensions.
The answer is that the __imp prefix refers to function stubs in the OBJ library for the DLL version of the CRT. This means your linker options are incompatible with your compiler options (linker set to static CRT or no CRT and compiler set to dynamic CRT).
In your case rather than the CRT itself it is another library, but the same idea.