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

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

问题描述

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

1> ------构建开始:项目:masksample,配置:调试Win32 ------
1>正在编译...
1> stdafx.cpp
1>正在编译...
1> masksample.cpp
1>将清单编译为资源...
1>正在链接...
1> LINK:上一个增量链接未找到或未构建C:\ Users \ DarekSz \ Praca \ cci \ Debug \ masksample.exe;执行完整链接
1>嵌入清单...
1> masksample-0个错误,0个警告
===========构建:1个成功,0个失败,1个最新,跳过0个==========

然后我继续构建另一个:

1> ------构建开始:项目:calibsample,配置:调试Win32 ------
1>正在编译...
1> stdafx.cpp
1>正在编译...
1> calibsample.cpp
1>将清单编译为资源...
1>正在链接...
1> LINK:最后一个增量链接未找到或未构建C:\ Users \ DarekSz \ Praca \ cci \ Debug \ calibsample.exe;执行完整链接
1>创建库C:\ Users \ DarekSz \ Praca \ cci \ Debug \ calibsample.lib和对象C:\ Users \ DarekSz \ Praca \ cci \ Debug \ calibsample.exp
1>嵌入清单...
1> calibsample-0个错误,0个警告
===========构建:1个成功,0个失败,1个最新,跳过0个==========

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

解决方案

有点晚了,但是也许其他人可以找到有用的提示.

顺便说一句,我不是c ++专家...

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

通常,在构建了dll的同时,您还为NON dll项目生成了其他文件(.exp,.lib).当您将dll项目的.h文件包含到应用程序项目中时,这可能会发生,该文件包含一个标有__declspec(dllexport)的类.

为避免链接程序认为您正在尝试包括一些.h文件以进行导出",请使用条件表达式来定义_declspec宏.

示例:

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

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

您现在可以在.h文件中

class DllExport MyClass {
 ...
}

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

#define _DO_NOT_EXPORT
#include "MyClass.h"

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>------ 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:\Users\DarekSz\Praca\cci\Debug\masksample.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>------ 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:\Users\DarekSz\Praca\cci\Debug\calibsample.exe not found or not built by the last incremental link; performing full link
1> Creating library C:\Users\DarekSz\Praca\cci\Debug\calibsample.lib and object C:\Users\DarekSz\Praca\cci\Debug\calibsample.exp
1>Embedding manifest...
1>calibsample - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

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.

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

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

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).

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

Example:

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

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

in your .h file you could have now:

class DllExport MyClass {
 ...
}

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天全站免登陆