Visual Studio 2005 链接器问题
我对 Visual Studio 很陌生,所以如果这是一个基本问题,我深表歉意。 我有一个包含多个项目的解决方案。 在项目 A 中,我有一组预先存在的文件,我向其中添加了一个新类。 项目 B 使用项目 A 中的新类中编码的功能。首先构建项目 A,并生成一个 .lib 文件,并将该 .lib 文件链接到项目 B 中。但是,当我去创建 .lib 文件时对于 Project BI,引用我添加的项目 A 中的新功能时出现链接错误。 将“dumpbin”命令与项目 A 生成的 .lib 文件一起使用,我注意到我添加的函数的符号不存在。 但是,在项目 A 中编译新类后创建的 .obj 文件确实包含这些符号。 知道为什么这些符号没有出现在项目 A 的 .lib 文件中吗?
I'm mostly new to Visual Studio, so I apologize if this is a basic problem. I have a solution which contains a number of projects. In project A, I have a pre-existing set of files that I added a new class to. Project B uses the functionality coded in that new class in Project A. Project A is built first, and a .lib file is generated, and that .lib file is linked into Project B. However, when I go to create the .lib file for Project B I get a link error, referencing the new functionality in Project A that I added. Using 'dumpbin' command with the .lib file generated from Project A, I notice that the symbols for the functions that I added aren't there. However, the .obj file created after compiling the new class in Project A does contains those symbols. Any idea why those symbols aren't then present in Project A's .lib file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设这些都是 DLL 项目。 在 Windows 上,您需要通过使用
__declspec(dllexport)
修饰符号来导出符号,或者需要使用 .DEF 文件来指示要导出的符号。使用
__declspec
,这通常是通过创建如下标头来完成的:然后,当您想要导出类的所有成员时,您可以编写:
并在编译Project时定义
PROJECT_A_EXPORTS
A 但不是项目 B。这样,您可以在两个项目之间共享相同的 MyClass.h 头文件。 编译项目 A 时,您将导出符号,而编译项目 B 时,您将导入符号。以下是有关 DEF 文件路径的一些信息。 不过,这可能很难维护,并且在 C++ 中,您需要列出每个符号的修饰名称,这可能很痛苦。
I assume that these are both DLL projects. On Windows you need to either export the symbols by decorating them with
__declspec(dllexport)
, or you need to use a .DEF file to indicate which symbols to export.With
__declspec
, this is usually accomplished by creating a header something like this:Then when you want to export all members of a class, you write:
And define
PROJECT_A_EXPORTS
when compiling Project A but not Project B. That way, you can share the same MyClass.h header file between both projects. When compiling Project A, you'll export the symbols, and when compiling Project B, you'll import the symbols.Here's some information on the DEF file route. This can be hard to maintain, though, and in C++ you need to list each symbol's decorated name, which can be a pain.