简体   繁体   English

为什么我的简单C ++控制台应用程序在Visual Studio 2015中看不到我的简单C ++静态库标头?

[英]Why won't my simple C++ console app see my simple C++ static library headers in Visual Studio 2015?

I followed the steps here to create a simple C++ static class library in Visual Studio 2015 and a C++ console app that uses the class library. 我按照此处的步骤在Visual Studio 2015中创建一个简单的C ++静态类库,并使用该类库创建一个C ++控制台应用程序。 https://msdn.microsoft.com/en-us/library/ms235627.aspx https://msdn.microsoft.com/en-us/library/ms235627.aspx

Everything worked perfectly. 一切正常。

(I called my header ScottyMathFuncs.h) (我称我的头为ScottyMathFuncs.h)

Then I tried adding a second class to the static library and it complied fine but the console application won't see the new header file for the second class. 然后,我尝试将第二个类添加到静态库中,并且编译良好,但控制台应用程序看不到第二个类的新头文件。 I tried deleting the original class and adding a new second class, which all complies fine in the static library project, but the console application won't see either of the new header files, and still sees and complies with the old header file that no longer exists. 我尝试删除原始类并添加一个新的第二类,这些类在静态库项目中都正常运行,但是控制台应用程序将看不到任何新的头文件,并且仍然可以看到并遵守旧的头文件,而没有不再存在。 It makes no sense. 这个不成立。

Here is some screen shots of the current solution that is not working: 以下是当前解决方案无效的一些屏幕截图:

VS 2015 Solution showing CPlusPlusConsoleApp project and CPlusPlusStaticLib project, with the console app cpp and the two class header and cpp files highlighted: VS 2015解决方案,显示了CPlusPlusConsoleApp项目和CPlusPlusStaticLib项目,其中控制台应用程序cpp以及两个类头文件和cpp文件突出显示: VS解决方案

Console Application Project Properties showing Path to Static defined in Additional Include Directory: 控制台应用程序项目属性,显示在附加包含目录中定义的静态路径: 控制台应用程序项目属性

Here is the Reference to the Static Lib I added to the Console Application Project: 这是我添加到控制台应用程序项目中的静态库的参考: 控制台应用程序参考

Here is a pic of the Console Application cpp where I am attempting to define the include for the new header files MyMathFuncs.h or MyMathFuncs2.h from the static library, but as you can see it only shows the old class that no longer exists. 这是控制台应用程序cpp的图片,我试图在其中定义静态库中新头文件MyMathFuncs.h或MyMathFuncs2.h的包含,但是如您所见,它仅显示不再存在的旧类。 控制台应用程序包括

I commented out the rest of the code in the console app that was so it would build. 我注释掉了控制台应用程序中其余的代码,因此可以构建它。 You can see from the build output at the bottom that even if I just type MyMathFuncs.h regardless of that fact that intellisense doesn't see it, the build fails saying it can't find the header. 您可以从底部的构建输出中看到,即使我只是键入MyMathFuncs.h,无论intellisense看不到它的事实,构建都无法说找不到标头。

Here is the MyMathsFuncs.h: 这是MyMathsFuncs.h: MyMathsFuncs标头

Here is MyMathsFuncs.cpp: 这是MyMathsFuncs.cpp: MyMathsFuncs CPP

Here is MyMathsFuncs2.h: 这是MyMathsFuncs2.h: MyMathsFuncs2标头

Here is MyMathsFuncs2.cpp: 这是MyMathsFuncs2.cpp: MyMathsFuncs2 CPP

In the process of re-documenting the issue, I actually just found the cause of the problem and fixed it. 在重新记录问题的过程中,我实际上只是找到了问题的原因并加以解决。 See the accepted answer. 请参阅已接受的答案。

In the process of doing such detailed documentation of the problem I found the cause of the issue!! 在对问题进行详细记录的过程中,我找到了问题的原因!!

I had originally created the static lib project in the wrong location, so I removed it from the project and then copied it to another location (the same dir as the solution) and the added the existing project at the new location back into the solution. 我最初在错误的位置创建了静态lib项目,因此我将其从项目中删除,然后将其复制到另一个位置(与解决方案相同的目录),并将现有项目添加到解决方案中。 The problem was that the reference in the console application was still pointing to the original copy of the project no longer linked to the solution, and this is why my console app was not aware of changes I was making to the project linked to the solution. 问题是控制台应用程序中的引用仍然指向不再链接到解决方案的项目的原始副本,这就是为什么我的控制台应用程序不知道我对链接到解决方案的项目所做的更改的原因。

Maybe this will help someone else..... 也许这会帮助别人.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM