引用头文件创建引用 dll 的应用程序时出错

发布于 2025-01-07 10:15:34 字数 1014 浏览 0 评论 0原文

我一直在尝试遵循 Microsoft Visual Studio 的演练,演练: 创建和使用动态链接库,因为我是初学者。

但是,我不断收到我难以理解和解决的错误。

首先它一直说有错误:

警告 C4627:“#include ”:在查找预编译头使用时跳过 1>将指令添加到“StdAfx.h”或重建预编译头

所以我做了一些在线搜索,看来我应该在行中添加:

#include“StdAfx.h”

进入 .cpp 文件 MyExecRefsDll.cpp,这是我在代码顶部所做的。

然后它出现了错误:

致命错误 C1083:无法打开包含文件:'MathFuncsDll.h':没有这样的文件或目录

我已包含此头文件的引用,这是我实际想要使用的头文件。我可以在下面看到这个参考: MyExecRefsDll 属性页\配置属性\c/c++\General,然后在我拥有的其他包含目录旁边,C:..etc..\DynamicLibrary\MathFuncsDll\MathFuncsDll.h

我读到了有关关闭使用预编译头的信息。这是我需要做的,但我不确定如何做?

我还阅读了一些有关使用 .lib 而不是 .dll 来引用动态链接库的内容。我尝试了这个,更改了 dll 的引用: MyExecRefsDll 属性页\配置属性\调试,在我键入的环境旁边,PATH=C:\Users...etc...\DynamicLibrary\Debug\MathFuncsDll.dll 我尝试将文件名的末尾更改为.lib,但没有任何改变,错误仍然是查找MathFuncsDll.h文件的问题。

谁能建议我如何使头文件正常工作,以便我可以成功构建解决方案?提前致谢。

I have been trying to follow the walkthrough for Microsoft Visual Studio, Walkthrough: Creating and Using a Dynamic Link Library, as I am a beginner.

However, I keep getting errors that I am having difficulty understanding and solving.

First of all it kept saying that there was an error:

warning C4627: '#include ': skipped when looking for precompiled header use
1> Add directive to 'StdAfx.h' or rebuild precompiled header

So I did some online searching and it appeared that I should add in the line:

#include "StdAfx.h"

into the .cpp file, MyExecRefsDll.cpp, which I did, at the top of the code.

It then came up with the error:

fatal error C1083: Cannot open include file: 'MathFuncsDll.h': No such file or directory

I have included a reference for this header file, which is the header file I actually want to use. I can see this reference under:
MyExecRefsDll property pages\configuration properties\c/c++\General, then next to Additional Include directories I have, C:..etc..\DynamicLibrary\MathFuncsDll\MathFuncsDll.h

I read about turning off using precompiled headers. Is this what I need to do, but I am not sure how?

I also read something about using .lib instead of .dll for referencing the dynamic link library. I tried this, changing the reference for the dll under:
MyExecRefsDll property pages\configuration properties\Debugging, next to Environment I have typed, PATH=C:\Users...etc...\DynamicLibrary\Debug\MathFuncsDll.dll
I tried to change the end of the file name to .lib instead, but nothing changed, the error was still at the problem with finding the MathFuncsDll.h file.

Can anyone suggest how I can get the header file to work so I can build the solution successfully? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忘东忘西忘不掉你 2025-01-14 10:15:34

Visual Studio 仅在无法找到头文件时才会显示该错误。为了解决这个问题,您应该检查项目设置。在您的问题中,您提到“我有,C:..etc..\DynamicLibrary\MathFuncsDll\MathFuncsDll.h”,在附加包含目录中您应该只有目录的名称,例如“C:..etc ..\DynamicLibrary\MathFuncsDll\"。
检查该文件是否确实存在,并仔细检查您是否正在编辑与当前构建配置相关的项目设置,即,如果您正在构建 Debug|Win32,则应该更改那里的附加包含目录。

Visual Studio only presents that error if it is unable to find the header file. In order to solve that you should check you project settings. In your question you refer that "I have, C:..etc..\DynamicLibrary\MathFuncsDll\MathFuncsDll.h", where in the Additional Include directories you should have only the name of the directory, like "C:..etc..\DynamicLibrary\MathFuncsDll\".
Check that the file is really there and also double-check that you are editing the project settings related to your current build configuration, i.e. if you are building Debug|Win32, you should change the Additional Include Directories there.

听闻余生 2025-01-14 10:15:34

我有完全相同的问题。我相信 VisualStudio 10 中有一个错误。

以下是演练中的麻烦步骤:

要引用动态链接库的头文件,必须
修改包含目录路径。为此,请从属性
页面对话框,展开配置属性节点,然后展开 C/C++
节点,然后选择常规。在“其他包含目录”旁边,输入
在 MathFuncsDll.h 头文件位置的路径中。

在这里,Visual Studio 将为您提供一个“浏览”按钮,以便您可以导航到所需的目录并选择它。执行此操作会将整个路径插入到其他包含目录中。

然而,这对我来说仍然不起作用。

我可以编译它的唯一方法是输入相对路径:

..\..\MathFuncsDll\MathFuncsDll\

I had exactly the same problem. I believe that there is a bug in VisualStudio 10.

Here is the troublesome step from the walkthrough:

To reference the header files of the dynamic link library, you must
modify the include directories path. To do this, from the Property
Pages dialog, expand the Configuration Properties node, then the C/C++
node, and select General. Next to Additional Include Directories, type
in the path to the location of the MathFuncsDll.h header file.

Here Visual Studio will give you a "Browse" button so that you can navigate to the desired directory and select it. Doing this will insert the entire path into the Additional Include Directories.

However, this still does not work for me.

The only way I could get it to compile was to type in the relative path:

..\..\MathFuncsDll\MathFuncsDll\

杯别 2025-01-14 10:15:34

对于这个问题有一个非常简单的解决方案。

在 Visual Studio 2010 中,在将

Project->Properties->Configuration Properties->C/C++->Precompiled Headers

“预编译标头”属性的值设置为“不使用预编译标头”下,按照列出的说明进行操作,演示应该不会出现错误。

There is a very simple solution to this problem.

In Visual Studio 2010 under

Project->Properties->Configuration Properties->C/C++->Precompiled Headers

Set the value for the "Precompiled Header" attribute to "Not Using Precompiled Headers," follow the instructions as listed, and the demo should build without error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文