<p>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.</p>

<p>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.</p>

<p>There are no such problems when the program is compiled with VS 2005.</p>

<p>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.</p>

[{'answer_id': 49392, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s not incorrect to link to an older library in the way you describe, but it doesn\'t surprise me you\'re seeing some odd behavior. Couple sanity checks:</p>\n\n<ul>\n<li>Are both files using the <strong>same versions</strong> of the <strong>same run-time libraries</strong>?</li>\n<li>Is your .EXE application "seeing" the same header files that the .LIB was built against? Make sure that the _WIN32_WINNT (etc.) macros are <a href="http://msdn.microsoft.com/en-us/library/aa383745.aspx" rel="nofollow noreferrer">declared properly</a>.</li>\n</ul>\n\n<p>And when you say .LIB, do you mean a true static library (mylib.lib) or an import library for a DLL (mylib.lib -> mylib.dll)?</p>\n\n<p>And what are the compile/link settings for your VS2008 executable project?</p>\n'}, {'answer_id': 49423, 'author': 'Timbo', 'author_id': 1810, 'author_profile': 'https://Stackoverflow.com/users/1810', 'pm_score': 5, 'selected': True, 'text': '<p>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.</p>\n\n<p>As a rule of thumb, you should always compile all C++ modules of a project with the same compiler and all settings/#defines equal.</p>\n\n<p>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.</p>\n'}, {'answer_id': 60671315, 'author': 'ManuelAtWork', 'author_id': 4792058, 'author_profile': 'https://Stackoverflow.com/users/4792058', 'pm_score': 0, 'selected': False, 'text': '<p><strong>Addition:</strong> As <a href="https://stackoverflow.com/a/49423/4792058">Timbo has pointed out</a>, VS 2005 and VS 2008 use different STL implementations. However, you can use VS 2008 to build against the old STL if VS 2005 is installed, too:</p>\n\n<ol>\n<li><p>Open your library project in VS 2008.</p></li>\n<li><p>Go to Tools > Options > Projects and Solutions > VC++ Directories</p></li>\n<li><p>Select your device platform in the drop-down at the top.</p></li>\n<li><p>Change the paths from the VS9 to the VS8 folders.</p></li>\n</ol>\n\n<p>This way, you can use VS 2008 to build libraries for use with VS 2005. (Worked for me.)</p>\n'}]
['https://Stackoverflow.com/questions/49330', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3315/']