execution error : Invalid Address specified to RtlValidateHeap( 003F0000, 00379488 )

I work on a project in which I use an external library which allows me to control a device.
In the documentation of the library, they say that we have to set "use runtime libraries" to "multithreaded dll" in project->settings->code generation

Before I added this library I used the runtime library "multithreaded". I kept this option because people at my work who used the same library as the one I want to add made it work with this setting.

The problem that I face is that when I execute my program (with the "multithreaded" option) I get the following execution error :
HEAP[name.exe]: Invalid Address specified to RtlValidateHeap( 003F0000, 00379488 )

I have read in msdn and other places that this could be due to the fact that I use the "multithreaded" runtime library instead of "multithreaded dll", so I tried to change that and now I get the following linker's errors :

libcmtd.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcmtd.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcmtd.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
libcmtd.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
...
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "libcmtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

So I tried to ignore the libraries "msvcrtd.lib", "libcmtd.lib", but it created linking errors (unresolved external symbols) in libraries included in my projects.

Could anyone suggest me something to solve this ? Could it be possible to either solve the linking problem with the "multithreaded dll" runtime library, or either suppress the execution error (the heap thing) with the "multithreaded" runtime library ?

Thanks for your help




 
zazarbAsked:
Who is Participating?
 
SteHConnect With a Mentor Commented:
You want get a debut version of the commercial library in most cases anyhow. So NO, its not stupid at all.

The bigger problem is to match CRT calls: A free from MT DLL will likely not work on pointer malloced with the static MT version (Same for new and delete). So you have to put the allocation and deallocation in parts with the same CRT version. This could be done by creating a DLL with the same convention as the part it inlcudes; ie create DLL statically linked MT and call the other library only from this DLL. The remainder of your app should then be MT DLL and can safely call the commercial DLL.

Differences in commercial and release version of libraries and you app should only manifest in the place where an error is detected. In debug some can be caught by ASSERTs, others by memory guards added whereas in the release version you likely find them when hitting a bad memory which doesn't need to be related to the actual position it occured.
0
 
SteHConnect With a Mentor Commented:
The linking errors come from the fact that now multithreaded (libcmtd) and multithreaded dll (msvcrtd) versions of the same (C Run Time) libraries are used. Only one is needed: the msvcrtd.lib should be included and libcmtd should be ommited. Can it be that other parts of that project are still using multithreaded non dll versions of the CRT libs?

The other problem is in connection with this: the heap has different blocks; one is used for multithreaded and another for dll version of the allocation functions. Allocations with one function can't be deallocated with a function from the other lib.
0
 
zazarbAuthor Commented:
Thanks for your answer, but when I ignore libcmtd.lib only (with the"debug multithreaded dll" runtime library), I still get a linking error :
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
nafxcwd.lib(olelink.obj) : error LNK2001: unresolved external symbol __mbctype
libcimtd.lib(filebuf.obj) : error LNK2001: unresolved external symbol ___pioinfo
name.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
SteHConnect With a Mentor Commented:
There are two choices to make for including CRT libraries:
single threaded, multi threaded and multi threaded dll is one list of choices. The other list is:
without STL, STL or old style STL support.
libcimtd.lib is old style STL (iostream support [#include <iostream.h>]) for multithreaded static linking.
nafxcwd is the mfc static link library.

It seems that you need to sort out what librarries are needed. Dependency walker is a great help when used on compiled (or better linked) code.
0
 
zazarbAuthor Commented:
I have found out new things concerning the problem I have.
I use a library which handles a commercial device. This library is supposed to work only in multithreaded dll.
I use another library for my project which works only in multithreaded -non dll.

I managed to make my program work in release version, the linker error happen only in debug version. It is a hassle if I want to debug other parts of my app...
So I wondered : is there a way to work in debug version, and specify that a specific subpart of the project must be considered in its release version ? (For example, is it completely stupid to use the release versions of the commercial library in debug mode ?).
Thanks


0
 
zazarbAuthor Commented:
Actually I was able to solve the problem, but by cheating with the commercial lib (ie finding other libs that could replace it where there were memory leaks). I guess the pb really came from internal pbs in the lib, which forced you to work in a specific configuration...
Thanks anyways for the info given in the posts, I learned things I didn't know.



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.