在VS2003中使用VS2005-lib [英] Use a VS2005-lib in VS2003

查看:92
本文介绍了在VS2003中使用VS2005-lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

我希望外面有人比我聪明:).
从VS2003 MFC项目访问以VS2005编写的静态库时,我遇到了这个奇怪的问题.代码使用本机C ++.

我在VS2003项目中使用静态绑定.

我可以很方便地访问库并执行方法,但是当我在VS2003中通过ref(或std :: vector)传递std :: string时,似乎VS2005中的内存位置偏移了4个字节,导致<删除的ptr =">和崩溃.

我将方法称为"Foo(std :: string& arg_szError);"
在VS2003中,我的字符串的地址为0x0013F4C0,但是当我在VS2005中调试Foo时,我的字符串的地址突然变为0x0013F4C4,其结果为已知.

有趣的是,它实际上工作了一段时间,但是我不得不将解决方案中的一些项目移到不同的目录,从那时起,我就遇到了这个非常烦人的问题.

我认为有些事情(很可能是我:()弄乱了代码生成和/或链接选项.
我认为这是一些有用的选项.

VS2003:
常规选项:应用程序(exe),在共享dll中使用MFC,而不使用ATL,MBCS
C/C ++:多线程调试DLL,默认结构成员对齐,__ cdelc
链接器:不忽略默认库

VS2005:
常规选项:静态库,使用标准Windows库,动态链接到ATL,MBCS
C/C ++:多线程调试,默认结构成员对齐,__ cdelc

使用2种不同IDE的主要原因是,我正在使用模板库来执行一些矩阵计算,这些计算仅适用于VS2005或更高版本,而我的主应用程序附带了为VS2003编写的第三方库(我尝试升级,但由于库中有一些MFC引用而失败,这些引用当然不属于该库.)

预先感谢您尝试帮助我解决这个问题!

Hey there,

I hope someone out there is alot smarter than I am :) .
I have this strange problem when accessing a static library written in VS2005 from a VS2003 MFC-project. Code is in native C++.

I use static binding in my VS2003-project.

I have no trouble accessing the lib, and executing the methods, but when I pass an std::string by ref (or an std::vector) in VS2003, it seems that the memory-location in VS2005 is shifted by 4 bytes, resulting in a <removed ptr=""> and a crash.

I call a method "Foo(std::string& arg_szError);"
In VS2003, the address of my string is 0x0013F4C0, but when I debug Foo in VS2005, the address of my string suddenly became 0x0013F4C4, with the known result.

The funny thing is that it actually worked for a little while, but I had to move some projects in my solution to different directories and since then, I get this very annoying problem.

I think something (most probably me :( ) messed up the code-generation and/or linking options.
Here are some options which, I think, could be useful.

VS2003:
General options: application (exe), use MFC in shared dll, not using ATL, MBCS
C/C++: Multi-threaded Debug DLL, default struct member alignment, __cdelc
Linker: not ignoring default libraries

VS2005:
General options: static library, use standard windows libraries, dynamic link to ATL, MBCS
C/C++: Multi-threaded Debug, default struct member alignment, __cdelc

The main reason for using 2 different IDE''s is that I''m using a template-library to do some matrix-calculations which only ships for VS2005 or higher, and my main-app comes with 3rd party libs written for VS2003 (I tried to upgrade, but it failed due to some MFC-references in the libs, which of course don''t belong there).

Thanks in advance for trying to help me out of this!

推荐答案

随着时间的推移,我学会了不要混用来自不同编译器的静态库.原因是现在您有两个版本的CRT在同一进程中运行,这是灾难的秘诀.最好的解决方案是为VS2005项目创建一个DLL,然后在VS2003项目中使用它.

-Saurabh
Over time I have learned not to mix static libraries from different compilers. The reason is that now you have two versions of CRT running in same process which is recipe for disaster. Best solution is to create a DLL for the VS2005 project and then use it in VS2003 project.

-Saurabh


Saurabh.Garg,

我实际上是用这种方式启动的,创建了一个dll,并通过动态链接在VS2003项目中使用了它.它工作了一段时间,但是在重新订购我的解决方案后,它搞砸了.一些同事建议我使用静态链接.
我在发布的问题中发现了一个小错误,就是我通过引用传递的std :: vector的地址在VS2003和VS2005中都相同,并且没有像传递std :: string时发生的那样移位了4个字节.但是我看不懂向量的元素.它总是看起来是空的.
Hi Saurabh.Garg,

I actually started it that way, created a dll, and used it in my VS2003-project by dynamically linking it. It worked for some time, but after re-ordering my solution, it got messed up. Some colleagues adviced me to use static linking.
I found a little error in my posted question, being that the address of the std::vector I pass by reference is the same in both VS2003 and VS2005, and not shifted by 4 bytes as happens when I pass a std::string. But I can''t read the elements of the vector. It always appears to be empty.


这篇关于在VS2003中使用VS2005-lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆