dev-C++ 中的头文件

发布于 2024-07-07 22:35:12 字数 606 浏览 7 评论 0原文

我正在尝试向 dev-C++ 添加头文件,但是当我编译它时它不起作用。 以下是我的具体步骤(对于我的示例,我试图让 mysql.h 工作):

  1. 将“mysql.h”复制到 c:\dev-c++\includes
  2. 检查 dev-C++ 工具 > > 编译器选项> 目录> c include 和 c++ include 的路径为“c:\dev-c++\includes”,
  3. 文件顶部包含 #include
  4. 在编译的

这是 dev-C++ 编译器告诉我的:

13 C:\Documents and Settings\Steve\Desktop\server code\setup1\main.c `mysql' undeclared (first use in this function) 

以及由于未找到头文件

我概述的步骤正确吗? 或者我还需要做些什么来编译头文件。

PS我尝试对VS2008做同样的事情(将mysql.h放在vs2008包含文件夹中,等等) 但仍然有同样的错误。 如果可能的话,我想坚持使用 Dev-c++。

I'm trying to add an header file to dev-C++ but when I compile it it doesn't work.
Here are my exact steps (for my example, I'm trying to get mysql.h to work):

  1. copy "mysql.h" into c:\dev-c++\includes
  2. check that in dev-C++ tools > compiler options > directories > c includes and c++ includes have the path to "c:\dev-c++\includes"
  3. include #include at the top of my file
  4. compiled

This is what the dev-C++ compiler told me:

13 C:\Documents and Settings\Steve\Desktop\server code\setup1\main.c `mysql' undeclared (first use in this function) 

As well as other errors due to not locating the header file

Are the steps I've outlined correct? Or is there something else I need to do to get the header files to compile.

P.S. I tried doing the same with VS2008 (put mysql.h in the vs2008 include folder, etc)
but still have the same error. I would like to stick with Dev-c++ if possible.

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

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

发布评论

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

评论(5

梅倚清风 2024-07-14 22:35:12

您没有说明如何将其包含在文件顶部。 如果你这样做了,这应该会起作用

#include "mysql.h"

,而不是

#include <mysql>

人们有时会犯的错误。

编辑:在指定其他包含目录时,也许尝试使用相对路径而不是绝对路径(正如您似乎所做的那样)? 我不知道这是否会产生影响(而且我没有时间检查),但我一直使用相对路径,并且它总是对我有用(无论如何,这也是很好的做法)。 因此,不要使用

C:\Projects\ProjectName\Include

之类的内容

,具体取决于您的项目文件结构。

You didn't say how you included it at the top of your file. This should work if you did

#include "mysql.h"

rather than

#include <mysql>

which is a mistake that people sometimes make.

EDIT: Perhaps try using relative paths rather than an absolute path (as you seem to be doing) when specifying additional include directories? I don't know if that would make a difference (and I don't have the time to check) but I've always used relative paths and it's always worked for me (it's also good practice anyway). So, instead of

C:\Projects\ProjectName\Include

something like

\Include or ..\Include depending on your project file structure.

眼睛会笑 2024-07-14 22:35:12

Dev-C++ 是 GCC 的一个端口,因此请尝试此页面: http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

请注意,您可能必须修改 Makefile。

Dev-C++ is a port of GCC, so try this page: http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html.

Note that you probably have to tinkle with the Makefile.

冬天旳寂寞 2024-07-14 22:35:12

我遇到了同样的问题......

您需要将 #include 放在“using namespace std;”之后,以便在标准名称空间中使用您的头文件。

对我来说它正在发挥作用。

最好的祝愿。

I had the same problem....

You need to put the #include after "using namespace std;", in order to use your header file in the standard namespace.

For me it is working.

Best wishes.

紫南 2024-07-14 22:35:12

在左侧,右键单击项目并选择“添加到项目”,然后选择头文件。

On the left side, right click the Project and choose "Add to Project", and then select the header file.

悲念泪 2024-07-14 22:35:12

它非常简单......

只需创建您的头文件并将其另存为 .h 扩展名。

然后使用 #include "file_name.h" 而不是使用 include

示例-
这是我的头文件。

#include<iostream>
     using namespace std;

     namespace Ritesh
         {
             int a;
             int b;
             void sum();
         }
     void Ritesh::sum()
         {
             cout<<a+b;
         }

然后使用它-

#include<iostream>
#include "Ritesh.h"
   using namespace std;
   using namespace Ritesh;
   int main()
       {
           a=4;b=6;
           sum();
       }

输出-
程序输出

Its very simple ...

Just make Your header file and save it as .h extension.

Then use #include "file_name.h" instead of using include

Example-
This is my header file.

#include<iostream>
     using namespace std;

     namespace Ritesh
         {
             int a;
             int b;
             void sum();
         }
     void Ritesh::sum()
         {
             cout<<a+b;
         }

Then use of it-

#include<iostream>
#include "Ritesh.h"
   using namespace std;
   using namespace Ritesh;
   int main()
       {
           a=4;b=6;
           sum();
       }

Output-
Output of program

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