I've been trying to solve this linker error for the last 3 hours, I keep getting errors saying that I have unresolved external symbol of _WinMainCRTStartup. Does anyone know what could be causing this error? I am using SDL's main function definition (SDL_main)
I also tried recreating the project incase something was accidentally changed, but the error persists.
The full output is here
https://gist.github.com/Joshhua5/73fe4235724d95e53f48
You're getting lots of unresolved external symbols, not just _WinMainCRTStartup. This usually indicates you're not linking a library you need to, and given the names of the functions it looks like it's the C runtime library (controlled with the /MTd etc. flags, or "C/C++ -> Code Generation -> Runtime Library" in the project properties dialogue.
I think I see the problem though; this line near the bottom:
4>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\OLDNAMES.lib : warning LNK4272: library machine type 'UNKNOWN' conflicts with target machine type 'X86'
... suggests you're using the VS2015 preview, and I don't imagine there's a release of SDL for that toolset yet, so I guess you're linking old libraries (which expect to be linked with an older toolset). Is that right? If so, you'll need to build SDL yourself.
Another possibility is simply that you've got the wrong subsystem type set - SDL will be expecting either /SUBSYSTEM:CONSOLE or /SUBSYSTEM:WINDOWS (set in "Linker -> System -> SubSystem"). Try choosing whichever one isn't chosen now.
Related
Configuration I have
Windows 10 64bit
Visual Studio Community 2017 with Visual C++ 2017
CMake 3.9.0
opencv 3.3.0
Aim
Goal is to build opencv as a static library (.lib) and include into a Visual C++ project which is a DLL. Everything should be compiled for x86 architecture or simply 32bit.
Process
Latest opencv distributive does not contain dll's compiled for 32bit system and therefore, I need to compile own version. According to the opencv 2.4 documentation on "installation in Windows". I have compiled the library with BUILD_SHARED_LIBS option disabled and configured target project as described in "how to build applications with OpenCV inside the Microsoft Visual Studio".
Compilation of my project fails with following errors (totally error count is greater than 800)
Error type 1
LNK2038 mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug'
doesn't match value 'MDd_DynamicDebug' in main.obj
\opencv_core320d.lib(alloc.obj)
Error type 2
LNK2005 "public: void __thiscall std::basic_ostream<char,struct
std::char_traits<char> >::_Osfx(void)" (?_Osfx#?$basic_ostream#DU?
$char_traits#D#std###std##QAEXXZ) already defined in
opencv_core320d.lib(system.obj) \msvcprtd.lib(MSVCP140D.dll)
Error type 3
LNK2001 unresolved external symbol _ippicviHSVToRGB_16u_C3R#24
\opencv_imgproc320d.lib(color.obj)
I believe it may be due to uncoordinated compilation options or erroneous configuration of my project, but because I am heavy Linux user I experience difficulties with setting up these things on Windows.
Update
After I have matched configuration shown in the screen below block of errors about code generation mismatch disappeared, but undefined references are still there.
Thank you for help!
To resolve "Error type 3" add *.lib files from "staticlib" dir to "Linker->Input->Additional Dependencies". For example "_ipp" symbols are defined in "ipp_iw.lib" and "ippicvmt.lib".
Just for info. I successfully built opencv from sources as a static and shared library (as opencv_world3**.lib) using MSVS 2012 and cmake 3.9.0. But also done that with MSVS 2017 community.
PS. Maybe a TYPO but you said that you use opencv 3.3.0 but in error messages there is opencv_core320d.lib
PPS. "Error type 1" is the result of using static debug runtime version in opencv_core (MTd) and dynamic debug runtime in your app (MDd)
I always have the same problems. This is why I have a property sheet ready for use.
The steps to follow for static compilation are:
Remember to Build the INSTALL project in the CMake generated Solution. Let's call $(OPENCV_DIR) the folder where the install happened (usually something like xxx\install). You can create an environment variable for this.
Add in front of [Configuration Properties]->[VC++ Directories]->[Include Directories] $(OPENCV_DIR)\include;. The semicolon is to separate paths.
Add in front of [Configuration Properties]->[VC++ Directories]->[Library Directories] $(OPENCV_DIR)\x86\vc15\staticlib;.
Match the runtime library linkage mode between OpenCV and your project. If you unselect BUILD_SHARED_LIBS by default the CRT is statically linked (/MT for Release or /MTd for Debug). If you want it dynamically linked deselect BUILD_WITH_STATIC_CRT. So, as you already realized, fix it in [Configuration Properties]->[C/C++]->[Code Generation]->[Runtime Library].
Copy all filenames matching *.lib (*d.lib for Debug) and add them in [Configuration Properties]->[Linker]->[Input]->[Additional Dependencies] separated by semicolons.
It's quite painful, so do it once in a Property Sheet and just include it when needed.
I have a common linker error in a situation where I do not understand why I get it. I changed a project from static linking (/MT) to dynamic linking (/MD). After this I get the following error:
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't
match value 'MT_StaticRelease' in XY.obj XXX [some folders]\XYZ.obj
The source files for XY and XYZ are both part of the same project. The project is compiled with /MD. I first thought that some files have not been updated in my rebuild, so I cleaned the build and rebuild the project. Since I still got the same error, I manually deleted the build folder containing the .obj files and rebuild the project. I still get the error.
A second effect I don't understand is that an included library (which I changed from the static version to the dynamic version) does not find several symbols:
Error LNK2001 unresolved external symbol __imp__strncat LAAPTOF_Fuzzy_XOP
[some folders]\ccc_vc120_md.lib(MxNET.obj)
etc...
When I include the static version of the library, these errors disappear but I get no error with respect to a runtime library mismatch, which I expected to get.
All these errors only show up for the 32 bit version of the project. The 64 bit version builds fine. I've checked all parameters and they are the same except where a different one is required for the 64 bit version.
Can anybody explain to me what I might be doing wrong?
I've solved the problem. My project used to be a visual studio 2010 project. I've been warned that converting a project to a newer version of visual studio does not always run smooth, even if the converter tells you so. I don't know if this was really the problem, but after setting up a new project file, everything links correctly.
I'm compiling a legacy Visual Studio 6.0 C++ application in Visual Studio 2015 and I've run into this error and searching the net hasn't yielded any useful information.
LNK2019 unresolved external symbol __except_handler4_common referenced in function __except_handler4 (MSVCRT.lib)
I understand that somewhere in the code is referencing a method no longer(?) present in current versions of MSVCRT. Is there a workaround / compiler flag for this?
The error message is actually saying the the function __except_handler4, defined in MSVCRT.LIB, references the undefined symbol __except_handler4_common. So it's not your code that's making the this reference, it's Visual Studio 2015's code.
The symbol __except_handler4_common is defined in vcruntime.lib. This file should be automatically be linked in. I'm not sure why it wasn't. Did you select the static runtime library in the project options ("Multi-threaded (/MT)"), but then manually add MSVCRT.LIB (part of the dynamic C runtime libary)?
In your library project, check Properties -> C/C++ -> Code Generation -> Runtime Library
Chances are it's set to "Multi Threaded Debug DLL" (/MDd).
If that's the case then try changing it to "Multi Threaded Debug" (/MTd) and rebuild (that worked for me).
The reason for this error depends.
For me it was "libcmt.lib" and "libcmtd.lib" listed explicitly among linker inputs, rather than by selecting it from "Runtime Library" field in GUI.
For me, I was linking to the objects of a static project from a non-static unit test. I tried setting the unit test to static build, but then the compiler (VC++ 2015) got the error An internal error has occurred in the compiler. I ended up setting both the main project and the unit test project to "Use MFC in a Shared DLL", and then it worked.
I've installed MS-MPIv5 from Microsoft and also the debugger for msmpi. In proejct properties in VS2012, I've changed C/C++ -> Additional include libraries adding "$(MSMPI_INC); $(MSMPI_INC)\x64" and also Linker -> All options->Additional Dependencies adding "msmpi.lib;", but VS is still giving me al lot of linker errors such as
error LNK2019: unresolved external symbol _MPI_Barrier#4
unresolved external symbol _MPI_Bcast#20
and so on, with all the mpi functions or type of variables. Is there something I forgot to change or add?
I haven't used 2012, but if it's similar to the older versions of VS then this detailed link may help. In general make sure to do these 3 things:
Add the "Additional Include Directories"
Add the "Additional Library Directories"
Add the "Additional Dependencies" (msimpi.lib)
It sounds like you may be missing the 2nd step?
Try $(MSMPI_INC)x64 (no \)
In my PC
MSMPI_INC=C:\Program Files (x86)\Microsoft SDKs\MPI\Include\
I have a template VS .NET 2003 project, which colleagues copy and customise when developing their software.
It appears the template was altered a while back to set the IgnoreSpecificLibrary property to have libcmt.lib for both release and debug builds (i.e. for both release and debug, the build should ignore libcmt.lib in the linker).
Some projects based on this have since been built, with the release build pulling in libcmtd.lib (evident by looking through the project .map file) which appears to have caused some runtime issues (i.e. a dialog window being flashed up as though a breakpoint had been set).
Does setting IgnoreSpecificLibrary to exclude libcmt.lib automatically make the project link against libcmtd.lib?
What is weird is that building the template (with the incorrect setting) links against libcmt.lib whereas some of the customised projects (though not all) link against libcmtd.lib.
Any ideas?
This is what happened:
After compiling the linker takes your object-files and create among others
a symbol table ,which has symol-request that have not been fullfilled.
Then the linker goes through your list of libraries trying resolve those
unfullfilled symbols. Since you ignore libcmt.lib ,your third-party library
has left or added some unresolved symbols and it contains a linker request
to resolve those from licmtd.lib (and maybe other libs as well) ,since it
was compilled with debug option.
If you hadn't ignored libcmt.lib those symbols would most likely be resolved
by libcmt.lib and there was no need to pull in stuff from libcmtd.lib (even though
it would be looked at to resolve other symbols that were still unfullfilled)
You may try to igmore libcmtd.lib also. If you now get unresolvd externals then
it was probebly no a good idea to ignore libcmt.dll.
Many projects ignore the libcmt.lib, because it conflicts with the dynamic version msvcrt.lib.
Ignoring libcmt in the linker make the project compile with msvcrt.lib