473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Debug library crashes when linked with Release build

I just converted a solution from Visual Studio 2003 to Visual Studio
2005 and the Debug mode seems to be running just fine, but the Release
mode crashes on the following code:

std::ifstream in("myfile.txt");
float value;
in >value; //The crash happens here in the getloc() function

The above code is actually from a library built in Debug mode that is
linked into the Release build of the executable. Does anyone have any
ideas of what could be causing this? Or how I could fix it (other than
switching the library to release mode, because that's currently not an
option)?

Thanks,
Dave
Apr 3 '08 #1
2 2672
The library is a static library?

There can be big problems linking to two versions of the same library.
Each will have its own set of internal variables, each will have its own
heap, one of them probably isn't even initialized, etc.

Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
"Dave Johansen" <da**********@gmail.comwrote in message
news:cf**********************************@8g2000hs e.googlegroups.com...
I just converted a solution from Visual Studio 2003 to Visual Studio
2005 and the Debug mode seems to be running just fine, but the Release
mode crashes on the following code:

std::ifstream in("myfile.txt");
float value;
in >value; //The crash happens here in the getloc() function

The above code is actually from a library built in Debug mode that is
linked into the Release build of the executable. Does anyone have any
ideas of what could be causing this? Or how I could fix it (other than
switching the library to release mode, because that's currently not an
option)?

Thanks,
Dave
Apr 3 '08 #2
On Apr 10, 10:53 am, Dave Johansen <davejohan...@gmail.comwrote:
On Apr 9, 12:44 pm, Dave Johansen <davejohan...@gmail.comwrote:
On Apr 8, 3:45 pm, Dave Johansen <davejohan...@gmail.comwrote:
On Apr 8, 3:33 pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
Dave Johansen wrote:
On Apr 8, 2:52 am, Ismo Salonen <Ismo.Salo...@codeit.fiwrote:
>--snip--
>It does no more work because some classes have different sizes in
>debug vs. release mode. In debug mode ( _DEBUG defined) the classes
>contains extra fields for runtime checks. When release mode is
>compiled the classes memory footprint is smaller thanm in debug mode
>and debug mode writes memory locaations it should not ( those, now
>nonexistent debug variables).
>This worked in 2003 because it did not have such sophisticated debug
>helpers ( e.g iterator debugging). Using such combination
>(debug&release) in same executable was never supported, it worked by
>pure luck (or if you *really* knew what to do) .
>br
>ismo
I think that the claim that it "worked by pure luck" is not correct.
It worked because there's no standard compliant reason why it
shouldn't. I understand that the debug mode now supports more advanced
You can't hide behind the standard here, because you defined _DEBUG, which
begins with underscore+capital letter and as such is reserved for the
compiler or library implementation. When you start messing with reserved
identifiers you are completely implementation-dependent.
Beyond that, the standard requires that the one-definition rule be
respected. Frequently this requires having the same macro definitions
across the whole project, including static libraries, because although ODR
doesn't apply to macros, macros control the definitions of other things.
checks and such, but there's no reason that this couldn't have been
done without maintain existing features (an additional preprocessor
directive that allowed the additional checks to be disable would have
solved the problem). I understand why things broke and the change
makes sense from a certain perspective, but claiming that it "has to
be that way" just isn't true.
I believe there are other macros (why would you need a new directive???)
that control the extra checks.
Dave
I agree 100% and I understand why things are the way they are, but I
still believe that they are this way by choice and not by some
external, uncontrollable force. The versions of Visual Studio prior to
2005 stand as a testament to this, because what I am trying to do was
allowed and functioned properly before Visual Studio 2005. I also
agree 100% that mixing debug and release libraries isn't recommended,
but that doesn't mean that it should be impossible.
Dave
I did a little more digging and it turns out that the iterator
debugging stuff can be disabled (which fixes the problem I was having)
by defining _HAS_ITERATOR_DEBUGGING as 0. You can read more about it
here:http://msdn2.microsoft.com/en-us/lib...39(VS.80).aspx
Thanks everyone for all of the help and advice,
Dave

I would like to make a correction and state that turning off the
iterator debugging didn't fix all of the problems that I was having
with mixing debug and release builds, so I guess that this is just a
semi-undocumented breaking change for Visual Studio 2005.

Dave
Hi,

I went through the same frustration when I moved our company software
from VS 2003 to VS 2005. I also tried to fix with the
_HAS_ITERATOR_DEBUGGING=0, but with partial success only. Is there a
way to "emulate" the VS2003 behavior with regards to mixing debug and
release CRT? From the thread below, I understand that the only clean
way out of my problems would be to revise all APIs and use only basic
data types in them...

Steve
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Song | last post by:
Hi, gurus, I am new with visual studio... I am trying to build a standalone C++ project by MS visual C++, the problem that I have is: if compile it as "Release" version, it crashes by a...
0
by: Adam Tomjack | last post by:
I'm trying to embed Python 2.3.5 into a C++ application on Windows XP. When I build my app with debug symbols and link to a debug build of Python, then my program seems to crash most (but not all)...
2
by: babyx | last post by:
The release build class library can only work with msvcr71d.dll and msvcp71d.dll exist. How to make this class library work on any machine without using the debug dlls? What are the project...
5
by: David++ | last post by:
Hi there, I have built a DLL in Visual C++ 6. When I build the DLL it builds fine for the debug version of the DLL (and this DLL works fine), however, I seem unable to build a Release version of...
6
by: Boni | last post by:
Dear all, I have following problem. I created a static libruary (mylib.lib). I compiled it with Multithreaded DLL runtime in release mode. Now I want to give out this library. But users who...
2
by: kevinding | last post by:
Hi All, We meet an evil condition for our project. Our project has 3 layers. A C# layer to do some business logic, and Managed C++ layer translate managed values to native ones or vice...
2
by: Epetruk | last post by:
Hello, I have a problem where an application I am working on throws an OutOfMemoryException when I run it in Release mode, whereas it doesn't do this when I am running in Debug. The...
4
by: nmrcarl | last post by:
I'm trying to upgrade a large project from VS 6.0 to VS 2005. After fixing a lot of things that changed (mostly sloppy coding in the original project that VS2005 didn't allow), I got the release...
6
by: Andrew Rowley | last post by:
I am having trouble getting debug and release builds to work properly with project references using C++ .NET and Visual Studio 2003. I created a test solution, with a basic Windows form C++...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.