为什么我的 Visual C++ .exe 项目构建会创建 .lib 和 .exp 文件? [英] Why does my Visual C++ .exe project build create .lib and .exp files?

查看:23
本文介绍了为什么我的 Visual C++ .exe 项目构建会创建 .lib 和 .exp 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由 3 个项目组成的解决方案.一个是静态库,两个是基于控制台的 .exe 文件,它们依赖并链接到这个库.它们的设置似乎相同.我构建了其中之一:

I have a solution consisting of 3 projects. One is a static library, and two are console-based .exe files that depend on and link against this library. Their settings seem to be identical. I build one of them:

1>------ 构建开始:项目:masksample,配置:调试 Win32 ------
1>编译...
1>stdafx.cpp
1>编译...
1>masksample.cpp
1>正在将清单编译为资源...
1>链接...
1>LINK : C:UsersDarekSzPracacciDebugmasksample.exe not found or not build by the last增量link;执行完整链接
1>嵌入清单...
1>masksample - 0 个错误,0 个警告
========== 构建:1 次成功,0 次失败,1 次更新,0 次跳过 ==========

1>------ Build started: Project: masksample, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>masksample.cpp
1>Compiling manifest to resources...
1>Linking...
1>LINK : C:UsersDarekSzPracacciDebugmasksample.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>masksample - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

然后我继续构建另一个:

Then I go on to building the other:

1>------ 构建开始:项目:calibsample,配置:调试 Win32 ------
1>编译...
1>stdafx.cpp
1>编译...
1>calibsample.cpp
1>正在将清单编译为资源...
1>链接...
1>LINK : C:UsersDarekSzPracacciDebugcalibsample.exe not found or not build by the last增量link;执行完整链接
1> 创建库 C:UsersDarekSzPracacciDebugcalibsample.lib 和对象 C:UsersDarekSzPracacciDebugcalibsample.exp
1>嵌入清单...
1>calibsample - 0 个错误,0 个警告
========== 构建:1 次成功,0 次失败,1 次更新,0 次跳过 ==========

1>------ Build started: Project: calibsample, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>calibsample.cpp
1>Compiling manifest to resources...
1>Linking...
1>LINK : C:UsersDarekSzPracacciDebugcalibsample.exe not found or not built by the last incremental link; performing full link
1> Creating library C:UsersDarekSzPracacciDebugcalibsample.lib and object C:UsersDarekSzPracacciDebugcalibsample.exp
1>Embedding manifest...
1>calibsample - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

为什么链接器这次会创建 .lib 和 .exp 文件?是否有一些选项可以打开和关闭我在不知情的情况下激活的功能?

Why does the linker create the .lib and .exp files this time? Is there some option to turn this on and off that I activated without knowing about it?

推荐答案

有点晚了,但也许其他人会觉得这个提示有用.

It's a bit late but, maybe someone else could find useful this hint.

顺便说一句,我不是 C++ 大师...

BTW I'm not a c++ guru...

在我的解决方案中,我有 3 个项目.一个是dll项目,其他是两个引用dll项目的Win32应用项目.

In my solution i have 3 projects. One is a dll project, the others are two Win32 app projects referencing the dll project.

通常,在构建 dll 后,您还会为非 dll 项目生成一些其他文件(.exp、.lib).当您将 dll 项目的 .h 文件包含到应用项目中时,可能会发生这种情况,该项目包含一个用 __declspec(dllexport) 标记的类.

Usually, with your dll built, you have also some others file generated (.exp, .lib) also for the NON dll projects. This can occour when you include a .h file of the dll project, into the app project, which contains a class marked with __declspec(dllexport).

为了避免链接器认为您试图包含一些 .h 文件以导出",请使用条件表达式来定义您的 _declspec 宏.

To avoid the linker think your are trying to include some .h files to "export" use a conditional expression to define your _declspec macro.

示例:

#if defined(_DO_NOT_EXPORT)
#define DllExport  
#else
#define DllExport __declspec(dllexport)
#endif

好的,假设您的 dll 项目中有一个 MyClass.h.

Ok, let's say you have a MyClass.h in your dll project.

在您现在可以拥有的 .h 文件中:

in your .h file you could have now:

class DllExport MyClass {
 ...
}

当您想将此 .h 文件包含到非 dll 项目中时,您只需定义 _DO_NOT_EXPORT 条件

When you want to include this .h file into a NON dll project, you have simply to define the _DO_NOT_EXPORT condition

#define _DO_NOT_EXPORT
#include "MyClass.h"

这篇关于为什么我的 Visual C++ .exe 项目构建会创建 .lib 和 .exp 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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