dev-C++ 中的头文件
我正在尝试向 dev-C++ 添加头文件,但是当我编译它时它不起作用。 以下是我的具体步骤(对于我的示例,我试图让 mysql.h 工作):
- 将“mysql.h”复制到 c:\dev-c++\includes
- 检查 dev-C++ 工具 > > 编译器选项> 目录> c include 和 c++ include 的路径为“c:\dev-c++\includes”,
- 文件顶部包含 #include
- 在编译的
这是 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):
- copy "mysql.h" into c:\dev-c++\includes
- check that in dev-C++ tools > compiler options > directories > c includes and c++ includes have the path to "c:\dev-c++\includes"
- include #include at the top of my file
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您没有说明如何将其包含在文件顶部。 如果你这样做了,这应该会起作用
,而不是
人们有时会犯的错误。
编辑:在指定其他包含目录时,也许尝试使用相对路径而不是绝对路径(正如您似乎所做的那样)? 我不知道这是否会产生影响(而且我没有时间检查),但我一直使用相对路径,并且它总是对我有用(无论如何,这也是很好的做法)。 因此,不要使用
C:\Projects\ProjectName\Include
之类的内容
,具体取决于您的项目文件结构。
You didn't say how you included it at the top of your file. This should work if you did
rather than
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.
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.
我遇到了同样的问题......
您需要将 #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.
在左侧,右键单击项目并选择“添加到项目”,然后选择头文件。
On the left side, right click the Project and choose "Add to Project", and then select the header file.
它非常简单......
只需创建您的头文件并将其另存为 .h 扩展名。
然后使用 #include "file_name.h" 而不是使用 include
示例-
这是我的头文件。
然后使用它-
输出-
程序输出
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.
Then use of it-
Output-
Output of program