VS2015内联函数的链接错误 [英] VS2015 Linking errors for inline functions
问题描述
我们有一个项目,我们从VS2013转换为VS2015.该项目在VS2013中构建良好,但在VS2015中给出了链接器错误.
We have a project that we converted from VS2013 to VS2015. The project built fine in VS2013 but gives linker errors in VS2015.
我在VS2013和VS2015中创建了一个简单的测试应用,可以重现错误.
I have created a simple test app in VS2013 and VS2015 where the errors can be reproduced.
- 该项目包含两个头文件.第一个标头(Declaration.h)包含函数声明,而第二个标头包含函数实现(Implementation.h).
- 调用该函数的文件(LinkingErrors.cpp)仅包含声明.h
- The project contains two header files. First header (Declaration.h) contains function declaration whereas second header contains function implementation (Implementation.h).
- The function is implemented as inline.
- The file where the function is called (LinkingErrors.cpp) only includes declaration.h
- This linked fine in VS2013 but fails in VS2015.
以下是我的主要观察结果:
Following is the main observation that I have:
发现以下项目属性的组合会导致VS2015中的链接错误,但会在VS2013中成功构建.
Found that combination of following project properties causes linking errors in VS2015 but builds successfully in VS2013.
- C/C ++属性->优化=>最大化速度(/O2)
- C/C ++属性->优化=>仅__inline(/Ob1)
如果两个选项均设置为禁用,则可以解决VS2015中的链接错误,但我认为这不是正确的解决方案.
If both the options are set to disabled, it resolves the linking errors in VS2015 but I don’t think that the correct solution.
VS2013和VS2015项目在以下位置共享:
The VS2013 and VS2015 projects are shared at:
https://www.dropbox.com/sh/z8j4yxjoa3sk5j5/AAD35EJTYdKcSnPQiM? = 0
Omkar Joshi
Omkar Joshi
推荐答案
您好 Omkar Joshi ,
Hi Omkar Joshi,
我下载了您的代码,发现您在vs2015项目中注释了以下代码.如果我删除评论,那么效果很好.
I downloaded your code and I found that you comment the following code on the vs2015 project. If I remove the comment, it works well.
//#include "Implementation.h"
最诚挚的问候,
王丽
这篇关于VS2015内联函数的链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!