printf / _vsnprintf_l / already defined in msvcrtd.lib(MSVCR120D.dll) - visual-studio

I have project where I want to import library. When I do that (import .lib files from library) and than call any function from library I get following errors:
"C:\Uz\myproj.vcxproj" (default target) (1) ->(Link target) ->
aziotsharedutil.lib(consolelogger.obj) : error LNK2005: printf already defined in msvcrtd.lib(MSVCR120D.dll) [C:\Uz\myproj.vcxproj]
aziotsharedutil.lib(socketio_win32.obj) : error LNK2005: _vsnprintf_l already defined in msvcrtd.lib(MSVCR120D.dll) [C:\Uz\myproj.vcxproj]
uamqp.lib(amqpvalue_to_string.obj) : error LNK2005: _vsnprintf_l already defined in msvcrtd.lib(MSVCR120D.dll) [C:\Uz\myproj.vcxproj]
C:\Dz\myproj.vcxproj\myproj.dll : fatal error LNK1169: one or more multiply defined symbols found [C:\Uz\myproj.vcxproj]
0 Warning(s)
4 Error(s)
Does anyone know how can i fix this?
I have following libraries imported in my project:
msvcprtd.lib
msvcrtd.lib
kernel32.lib
ole32.lib
aziotsharedutil.lib //imported Library .lib file
uamqp.lib //imported Library .lib file
eventhub_client.lib //imported Library .lib file
Advapi32.lib
Crypt32.lib
Ws2_32.lib
Secur32.lib
ucrt.lib
vcruntime.lib
Note 1
All 3 projects that are built as Static Link Library .lib, have same settings Multi-threaded Debug DLL (/MDd), same as my project.
Thanks!

Compiled with same version of compiler and that solved my problem!

Related

getting nafxcwd.lib(timecore.obj) error lnk2001 unresolved external symbol __mbctype after header-include from other project

I made a new project for unittesting with googleTest. I then added a source file from another project to test it. I then got severeal linker errors:
nafxcwd.lib(timecore.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcwd.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcwd.lib(filelist.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
The key options in my projects are:
Testproject:
Runtime Library: Multithreaded Debug DLL (necessary for googleTest)
Use of MFC: Shared DLL
productive project: (this should actually not matter)
Runtime Library: Multithreaded Debug DLL
Use of MFC: Use MFC in a static library
Even if I copy all the options and files from the productive project with MFC as shared DLL these messages get thrown.
The file, that was imported to the testproject had the "stdafx.h"-include that was resolved to the productive projects one.
There,
#include <afxwin.h>
was included. Checking that one turned out, that for shared MFC-DLL, you need to
#define _AFXDLL
in your project / before the afxwin-include. Otherwise you get these errors.

Using tinyxml2 with a Visual Studio, Visual C++ MFC Application

I'm trying to get accustomed to both MFC development and Visual Studio so I have installed Visual Studio 2012 RC and have created a simple MFC Application. Currently the application is little more than the MFC Wizard generated for me.
I decided I wanted to incorporate an XML Library so I found this one on github. I download the ZIP file with the source code, unzip it and then in Visual Studio I goto the solution explorer, choose my solution, right click and choose "Add" > "Existing Project". I select the project file for the source code and it appears in my Solution Explorer tree.
I test the code compiles and it does. However I'm not quite sure how to use it from my current solution.
I try to use this code in my doc:
#include "../../TinyXML2/leethomason-tinyxml2-a3efec0/tinyxml2.h"
<...snip...>
BOOL LoadDocumentFromXML(const CString& filename) {
CT2CA pszConvertedAnsiString (filename);
std::string s(pszConvertedAnsiString);
tinyxml2::XMLDocument doc(true);
if (tinyxml2::XML_NO_ERROR != doc.LoadFile(s.c_str())) {
return FALSE;
}
return TRUE;
}
However I get this linker error when I try to build the project:
------ Build started: Project: GraphApp, Configuration: Debug Win32 ------
GraphAppDoc.cpp
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: __thiscall tinyxml2::XMLDocument::XMLDocument(bool)" (??0XMLDocument#tinyxml2##QAE#_N#Z) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML##YAHABV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z)
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall tinyxml2::XMLDocument::~XMLDocument(void)" (??1XMLDocument#tinyxml2##UAE#XZ) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML##YAHABV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z)
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: int __thiscall tinyxml2::XMLDocument::LoadFile(char const *)" (?LoadFile#XMLDocument#tinyxml2##QAEHPBD#Z) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML##YAHABV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z)
C:\Users\Phill\Documents\Visual Studio 2012\Projects\GraphApp\Debug\GraphApp.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
In the solution explorer I select my MFC application project, right click and choose "Dependencies". I make sure the MFC app is set to be dependent on tinyxml project and I ensure the "Build Order" is correct (tinyxml first). I also goto into "References..." and add tinyxml there too. I even add the debug directory of tinyxml to my MFC app's include path in project properties as well. What am I missing please?
Ok it turns out I didn't read the documentation fully. Reading the XML attached the project here states:
It is one header and one cpp file. Simply add these to your project
and off you go.
So I did this. Then I got some compiler warnings:
------ Build started: Project: GraphApp, Configuration: Debug Win32 ------
tinyxml2.cpp
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(24): warning C4627: '#include "tinyxml2.h"': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(26): warning C4627: '#include <cstdio>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(27): warning C4627: '#include <cstdlib>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(28): warning C4627: '#include <new>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(29): warning C4627: '#include <cstddef>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(1834): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So then I selected "tinyxml2.cpp" in the solutions explorer, right clicked, went to properties. In properties under "C++" I went to "Precompiled Headers" and changed the option that read:
Precompiled Header: Use
to
Precompiled Header: Not using precompiled headers
Then it magically worked!

linking to a static 0MQ library in VS

This may be a Visual Studio question more than anything else...
I'm trying to build a 0MQ C++ example using VS10 and ZeroMQ 2.2.0.
I downloaded the windows sources and tried to follow these instructions in order to build 0MQ statically. Specifically:
Switched to Release
For all 7 projects in the solution:
set General\Configuration Type to Static library (.lib)
set C/C++\Code Generation\Runtime Library to Multi-threaded (/MT)
added ZMQ_STATIC to C/C++\Preprocessor\Preprocessor Definitions
Updated zmq.h and zmq_utils.h so that if _MSC_VER and ZMQ_STATIC are defined then DLL_EXPORT will also be defined
At this point 0MQ seems to build well.
Created an empty console project:
switched to Release
added a single cpp file with the example linked above
changed random to rand, srandom to srand and snprintf to _snprintf
set C/C++\Code Generation\Runtime Library to Multi-threaded (/MT)
added ...\zeromq-2.2.0\include folder to C/C++\General\Additional Include Directories
added ...\zeromq-2.2.0\builds\msvc\Release\*.lib to Linker\Input\Additional Dependencies
However I still receive the following linking errors:
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_bind
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_close
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_errno
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_init
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_data
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_strerror
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_socket
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_init_size
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_term
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_close
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_send
What have I missed?
You should add ZMQ_STATIC to C/C++\Preprocessor\Preprocessor Definitions in your "empty console project" too. Otherwise, when you compile your application, ZMQ_EXPORT in zmq.h is defined as __declspec(dllimport), and as a result, MSVC looks for __imp__zmq_* symbols instead of zmq_*
I had similar errors - not when trying to statically link, but just trying to create a ZMQ project and link the .lib 'stubs' for the dll.
In my case it was because I was trying to link the 64-bit libraries into a 32-bit project. I had downloaded the wrong version. When I got the right ones, ie x86 instead of x64, it worked.
Is the static linking very important to you? If not, you can try out the second answer by elnino_9 here. Elaborating elnino_9's answer:
Download the sources and unzip to some local folder (say C:\dev\zeromq).
Go to C:\dev\zeromq-2.2.0\builds\msvc and open the msvc.sln solution. MS2010 will upgrade from a VS2008 to a VS2010 project
Build all of the projects.
The build should generate the two following files:
C:\dev\zeromq\lib\libzmq.lib - this is what you will need to reference in your project's linker options
C:\dev\zeromq_boaz\builds\msvc\Release\libzmq.dll - this you will need to copy to the same folder as your project's executable in order to run it (if your build was configured to 'Debug', the path would be C:\dev\zeromq\builds\msvc\ Debug \libzmq.dll)
Create your solution and project. Do the following:
In the Solution Explorer, right-click on you project, and select 'Properties' (at the very bottom).
Navigate to 'C/C++ --> General --> Additional Include Directories' and add C:\dev\zeromq\include. This will reference 0MQ's header files.
Navigate to 'Linker --> Input --> Additional Dependencies' and add the full path to the 'libzmq.dll' file from the previous step.
Build your project - this should go without errors now.
Copy 'libzmq.dll' to the same folder as your executable - your project should now run.
Some comments:
I am not sure why you need to reference the 'libzmq.lib' file. It is not needed by the executable (you can delete it, and it will still run, as the necessary logic resides in the dll). Can someone explain this?
Notice one caveat in the example for Windows users - the second binding statement (publisher.bind("ipc://weather.ipc");) will cause an exception. As explained here (though in fine-print), the Inter-Process Transport is not supported on Windows.
EDIT
I think the answer to my first comment can be found in MSDN:
"When the source code for the calling executable is compiled or assembled, the DLL function call generates an external function reference in the object code. To resolve this external reference, the application must link with the import library (.lib file) provided by the maker of the DLL."

error LNK2001: unresolved external symbol _CLSID_XYS

There is one idl file defined in microsoft sdk which is not available in VS2005. I am using some of the interfaces from that IDL.
Now this works fine on VS 2010 . I want to make it compile on VS2005.
I copied the header file to my project directory. But it is giving me compilation error.
When I looked into header file , the class id is defined in it as
EXTERN_C const CLSID CLSID_Xyz.
Now it is defined as extern so it means it should be declared somewhere else in code.
So my question is just including .h file is sufficient or do I need to also include _i.c file.
Any suggestions
Once you examine that _i.c file you'll see the indeed the CLSID constants are defined there. So yes, you need to incorporate that .c file into you program - either by #including it into a .c or .cpp file or just by adding it to your project so that it compiles separately and then links into the final binary.

How to resolve the following linker errors in Visual Studio?

Here is My scenario. I have a project which contains 30 subprojects. In one of the projects I have used CLR (common language runtime) so I modified its runtime with /mdd (multi threaded debug DLL).
Individually all the projects are built successfully. But when I try to compile the main
project I am getting the following linker errors:
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
LIBCMTD.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(invarg.obj) : error LNK2005: __invalid_parameter already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(crt0.obj) : error LNK2005: _mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj)
LIBCMTD.lib(fclose.obj) : error LNK2005: _fclose already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(printf.obj) : error LNK2005: _printf already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(mbstowcs.obj) : error LNK2005: _mbstowcs already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(dbgrptw.obj) : error LNK2005: __CrtDbgReportW already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(wcstombs.obj) : error LNK2005: _wcstombs already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(tzset.obj) : error LNK2005: __tzset already defined in MSVCRTD.lib(MSVCR80D.dll)
LIBCMTD.lib(stricmp.obj) : error LNK2005: __stricmp already defined in MSVCRTD.lib(MSVCR80D.dll)
How to resolve these all?
LIBCMTD is the debug version of the static multi-threaded C runtime library. MSVCR80D is a debug version of the DLL-based multi-threaded C runtime library. Some of your sub-projects are calling for one, some the other. It's a Microsoft mess, but you have to deal with it. Pick one, say, Multi-threaded debug DLL, and use it exclusively for the Debug version of your project and all sub-projects. The Microsoft license (I am told) requires that you use a non-debug version for released software.
See the following for more info: CLICK.
Seems like some of your projects use static runtime library. (And you have chosen dynamic for one of your projects)
This combination is unsupported.
Reminds me of: Linker errors between multiple projects in Visual C++

Resources