Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2005 & 2008 library linking

Is it correct to link a static library (.lib) compiled with VS 2005 with a program which is compiled with VS 2008? Both library and my program are written in C++. This program is run on Windows Mobile 6 Professional emulator.

This seems to work, there are no linking errors. However the program crashes during startup because strange things happen inside the linked library. E.g. lib can return a vector of characters with size of big negative number.

There are no such problems when the program is compiled with VS 2005.

What is even more strange the problem is only when using release configuration for the build. When compiling using debug configuration the problem doesn't occur.

like image 569
Greg Dan Avatar asked Dec 10 '22 23:12

Greg Dan


1 Answers

VS2005 and VS2008 use different STL implementations. When the VS2005 code returns a vector, the object has memory layout different from what VS2008 expects. That should be the reason for the broken values you see in the returned date.

As a rule of thumb, you should always compile all C++ modules of a project with the same compiler and all settings/#defines equal.

One particular #define that causes similar behaviour is the SECURE_SCL #define of VS2008. Two modules compiled with different settings will create exactly your problems, because #defining SECURE_SCL introduces more member variables to various C++ library classes.

like image 87
Timbo Avatar answered Dec 21 '22 22:12

Timbo