Sign in to follow this  
K-vak

Plz explain LNK2019 error in MS VC++ 2008 re: use of string

Recommended Posts

Greets all, I have a question and this is killing me. I am trying to write a program in Microsoft's Visual C++ 2008 Express Edition compiler. I have a lot of programming experience with the language, but I can't figure out how to fix this LNK2019 unresolved external error. The message says: Warning 1 warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library libcpmtd.lib Error 2 error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z) libcpmtd.lib Error 3 error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z) libcpmtd.lib I have no idea what these libraries are or what to do with them and as far as I know I am using the included files correctly. This problem appears (if I've understood the not-so-helpful help files) to come from a reference to a function that the compiler can't find. I'm not using any extern commands and have applied the 'using namespace std' to the top of the header file that includes <string>, <vector> and <stdlib.h>. The problem is that I don't understand this error well enough to even know where to look for the problem. Any help would really be appreciated as I've spent the last 3 hours trying to solve this problem (which can probably be done with a single puncuation mark!) TIA, K-vak

Share this post


Link to post
Share on other sites
It looks like you are linking in both the debug (libcpmtd.lib) and the release (libcmt.lib) versions of the C Run-time library. This could be because a library you are linking is compiled in release mode, and your project is being compiled in debug mode. Are you linking any external libraries? Have you tried the /NODEFAULTLIB:library libcpmtd.lib flag to see what happens? This will exclude the debug runtime from getting linked in, which could cause some problems for you if you want to debug.

Share this post


Link to post
Share on other sites
I have used the /NODEFAULTLIB:"libcpmtd.lib" command. What happens is that I get several more LNK2019 errors in main.obj and the warning doesn't go away....

Share this post


Link to post
Share on other sites
It means that one lib or dll you are using links to the release CRT (i.e. /MD), and another lib/dll/exe project is linking to the debug version (/MDd). Somewhere you have a mismatch between a debug and release version you need to sort out. The /NODEFAULTLIB:"libcpmtd.lib" isn't going to help you here, you just need to go through each project and make sure the C++/code generation/runtime lib is set the same for each project (i.e. /MD for all release versions, and /MDd for all debug versions).

Share this post


Link to post
Share on other sites
What external libraries are you linking to your project? And, if any, are you linking the debug versions of those libraries? If you aren't linking any, then it is a mismatch of build types in your own projects.

Share this post


Link to post
Share on other sites
I havn't explicitally (sp?) linked any external files. That's one of the reasons that this is confusing me. And as far as the debug/release versions of libraries, I'll admit that I din't know a lot about those. I am choosing the debug option in the compiler, but all of the build options are still set to their defaults... I tried to create a new project and see if I could replicate the problem, but no luck: it built fine in the new project....

However you got me thinking and I build the program with Release configurations. Everything works fine there, but I can't build in Debug. Any suggestions?

{EDIT}
Okay, I followed your advice and it builds after I set the Runtime Library in the Debug to the same as the one used in Release. So first off, thanx! Secondly, is this generally correct? I mean, I'm now using the non-debug version of the library in my debug build, that isn't going to cause any more problems down the road is it?

K-vak

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this