简体   繁体   中英

vs2010 debug vs release: why the stl list is interpret wrong

I have a program passing a stl list to an dll, when both modules are in debugging mode, everything works fine. When change the dll to release mode, the passing does not work any more. I checked the list in the main app (debugging version) and examined the list size to be 16 bytes, immediately in the dll I examined the list size now changes to 12 bytes. and everything in the list are wrongly interpret. I checked the compiler option and has doubt on the structure alignment, but did not get any clue. Anybody can give me some hints? Thanks a lot.

passing structure:

class data
{
int
int
char*
double
}

class datalist
{
int 
int 
int 
list<data> list1
list<data> list2
};

passing mechanism:

fun(const datalist& dl)

*More clarifications:

main app (debug) + dll (debug): work fine
main app (release) + dll (release): does not work
main app (debug) +dll (release): does not work

both modules are compiled with the same compiler vs2010*

Your DLL is using a different version of the C++ standard library than your application is, so each has it's own (incompatible) version of std::list . You have to rebuild your DLL with the same compiler and configuration you're building your application with (Visual Studio 2010, Release).

main app (debug) + dll (debug): work fine
main app (release) + dll (release): does not work
main app (debug) +dll (release): does not work

Native DLL's are a very raw low level mechanism. If the compiler of the App and the DLL have different settings, there's no inherent way for either side to know that the other is making different choices. So you as the developer have to ensure that everything is compatible.

In the case of debug vs release, the differences are often too significant. So just don't ever mix things like that.

For the case of your release builds not working together, you should check over all the compiler/linker settings on each project and ensure that they are compatible (which generally means having them exactly the same).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM