VS2003和VS2010中静态链接库的不同处理 [英] Different handling of statically linked libraries in VS2003 and VS2010

查看:153
本文介绍了VS2003和VS2010中静态链接库的不同处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i在Visual Studio 2003和2010中经历了以下非常奇怪的行为/差异:



将在VS2003中创建两个单独的项目。其中一个是构建为MFC扩展DLL(名为MFC_Extension_DLL),另一个是构建为MFC DLL(名为MFC_USINGDLL)。它们将在Visual Studio 2003的两个单独的应用程序实例中创建。



在MFC_Extension_DLL内部,一个名为MyClass.h的文件和另一个名为MyClass.cpp的文件将在创建。在这两个文件中,将分别写下类的适当声明和成员函数的定义。在Header文件中,AFX_EXT_CLASS用于告诉编译器必须导出类。



在MFC_USINGDLL内部,将包含MyClass.h文件直接来自MFC_Extension_DLL的项目目录内部。感谢AFX_EXT_CLASS宏,编译器知道此时必须在此处导入类。现在在任何方法中,MyClass类都将被实例化,并且将调用其中一个公共方法。

到目前为止,链接器不起作用=>未解决的外部符号。一切都好。



现在,在MFC_USINGDLL的打开解决方案中,将添加MFC_Extension_DLL项目。仍然没有任何作用。

但是现在,在MFC_USINGDLL的项目依赖项中,将添加对MFC_Extension_DLL的依赖。

WTF?链接器运行得很大......而且没有任何静态链接到所需的导入库MFC_Extension_DLL.lib!



最后一次测试:我在VS2010中执行完全相同的步骤。尽管项目依赖,但链接器由于未解析的成员函数而停止。



请问,有人可以解释一下这个吗?





您诚挚的,



Allgaeuer

Hello everyone,

i experienced the following very strange behavior/difference in Visual Studio 2003 and 2010:

Two seperate projects will be created in VS2003. One of them is build as a MFC extension DLL (named MFC_Extension_DLL) and the other one is build as a MFC DLL (named MFC_USINGDLL). They will be created in two seperate application instances of Visual Studio 2003.

Inside of the MFC_Extension_DLL, a file called MyClass.h and another one called MyClass.cpp will be created. In those two files, respectively the appropriate declaration of the class and the definitions of the member functions will be written down. Within the Header file, AFX_EXT_CLASS is used to tell the compiler, that the class has to be exported.

Inside of the MFC_USINGDLL, the MyClass.h file will be included directly from inside of the project directory of the MFC_Extension_DLL. Thanks to the AFX_EXT_CLASS macro, the compiler knows at this point it has to import the class here. Now in any method, the MyClass class will be instantiated and one of the public methods will be called.
So far so good, the linker does not work => unresolved external symbol. Everything ok.

Now, in the opened solution of the MFC_USINGDLL, the MFC_Extension_DLL project will be added. Still nothing works.
But now, in the project dependencies of the MFC_USINGDLL, a dependency to the MFC_Extension_DLL will be added.
WTF? The linker runs greatly... and this without any statically linking to the required import library MFC_Extension_DLL.lib!

One last test: I perform exactly the same steps in VS2010. Despite the project dependency, the linker stops because of the unresolved member function.

Please, could somebody explain me this?


Yours sincerely,

Allgaeuer

推荐答案

好的,我找到了解决方案。

请看以下链接:



Visual Studio 2010不会自动从静态库中依赖应该依赖的项目 [ ^ ]



什么是链接库Dependenc y链接器选项实际上在Visual Studio 2010中做了什么? [ ^ ]
Ok, i found the solution.
See the following links:

Visual Studio 2010 not autolinking static libraries from projects that are dependencies as it should be supposed to[^]

What does the "Link Library Dependency" linker option actually do in Visual Studio 2010?[^]


我不是非常关注这个故事,而是100%听起来你在__declspec(dllimport)和__declspec(dllexport)符号中混淆了一些东西。确保你有这些以及使用它们的宏符号设置正确。
I''m not following the story quite 100% but it sounds to me that you have something mixed up in the __declspec(dllimport) and __declspec(dllexport) symbols. Make sure that you have these and the macro symbols using them set up correctly.


这篇关于VS2003和VS2010中静态链接库的不同处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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