为什么我的 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 文件时间?是否有一些选项可以打开和关闭我在不知情的情况下激活的选项?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然有点晚了,但是也许其他人会发现这个提示有用。
顺便说一句,我不是 C++ 大师...
在我的解决方案中,我有 3 个项目。一个是 dll 项目,其他是两个引用 dll 项目的 Win32 应用程序项目。
通常,在构建 dll 后,您还会为非 dll 项目生成一些其他文件(.exp、.lib)。当您将 dll 项目的 .h 文件包含到应用程序项目中(该项目包含标有 __declspec(dllexport) 的类)时,可能会发生这种情况。
为了避免链接器认为您正在尝试包含一些要“导出”的 .h 文件,请使用条件表达式来定义 _declspec 宏。
示例:
好的,假设您的 dll 项目中有一个 MyClass.h。
在您的 .h 文件中,您现在可以拥有:
当您想要将此 .h 文件包含到非 dll 项目中时,您只需定义 _DO_NOT_EXPORT 条件
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:
Ok, let's say you have a MyClass.h in your dll project.
in your .h file you could have now:
When you want to include this .h file into a NON dll project, you have simply to define the _DO_NOT_EXPORT condition
如果从可执行文件中导出一个或多个函数,这是正常现象。
This is normal if one or more functions is/are exported from your executable.