Linking the VS 2005 and 2008 Library

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

This seems to work, no communication errors. However, the program crashes during startup because strange things happen in the linked library. For instance. lib can return a vector of characters with the size of a large negative number.

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

Even stranger, the problem only occurs when using the release configuration for assembly. When compiling using the debug configuration, the problem does not occur.

+4
source share
2 answers

VS2005 and VS2008 use different STL implementations. When the VS2005 code returns a vector, the object has a memory layout different from what VS2008 expects. This should be the cause of the erroneous values โ€‹โ€‹that you see in the returned date.

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

One specific #define that causes this behavior is SECURE_SCL #define VS2008. Two modules compiled with different settings will create exactly your problems, because #defining SECURE_SCL introduces more member variables into different classes of the C ++ library.

+11
source

It is not correct to reference an older library as you describe, but it does not surprise me that you see strange behavior. Security check:

  • Both files use the same versions of the same runtime libraries ?
  • Is your .EXE application โ€œseeingโ€ the same header files with which .LIB was created? Make sure the _WIN32_WINNT macros (etc.) are declared correctly .

And when you say .LIB, do you mean the real static library (mylib.lib) or the import library for the DLL (mylib.lib -> mylib.dll)?

And what are the compilation / link options for the VS2008 executable project?

+2
source

Source: https://habr.com/ru/post/1276592/


All Articles