需要基本示例代码编译帮助 - 我无法让任何 SDK 示例正常工作

发布于 2024-11-05 22:15:53 字数 1105 浏览 2 评论 0原文

我对 C++ 很陌生;我现在已经在各种应用程序上使用了多个 SDK,每次都会遇到无法编译“示例代码”的问题。这是一个非常广泛的问题,基本上涉及通过网络给出的任何示例代码 - 编译的标准程序是什么?我知道如何编译我自己编写的代码,但是当给定一个包含多个 CPP 和 H 文件的大型项目时,我该从哪里开始呢?我的第一个调用端口是在 Dev-C++ 中打开“main.cpp”并点击“编译”按钮,通常会引发有关头文件不可用等错误。

我不会给出具体的例子,因为这种情况已经发生过好几次了。我觉得作为一个开始掌握 C++ 的人,如果我能从有效的代码开始并自己调整它,而不是必须摸索着一点一点地构建东西,我会学得更快。

最近的例子是一家公司提供的一组示例代码,其中有 10 个文件:

-Arial.ttf
-demo_resources.rc
-icon.ico
-main.c
-simple.dsp
-simple.dsw
-simple.exe
-simple.h
-trial.c
-trials.c

运行 .exe 文件绝对没问题;但是,如果我打开 main.c 并按编译,我会收到许多错误消息。举个例子,main.c 中的前两行代码是:

#include "simple.h"
#include <sdl_text_support.h>

仅此一项就发出了错误消息:

1: expected unqualified-id before "public"
1: expected `,' or `;' before "public"
2: In file included from trial.c

显然我做了一些非常错误的事情,因为这段代码必须在过去为其他人编译才能生成 .exe 文件。同样,这不是一个孤立的问题,我一直遇到这个问题。

由于 Dev-C++ 完全可以处理普通的旧 C 文件,因此我看不出这是问题所在。其次,simple.h 肯定包含在正确的目录中。但第二个包含文件 sdl_text_support.h 显然不在我上面的文件列表中。我搜索了 SDK 的其余部分,发现该文件潜伏在其他地方。如何使用 Dev-C++ 显式引用头文件的位置?

任何有关如何编译预制项目的一般教程或任何类型的帮助将不胜感激。

I'm very new to C++; I've worked with several SDKs now on various applications and every time come across the problem that I can't get the 'example code' to compile. This is a very broad question basically regarding ANY example code that is given over the net - what is the standard procedure to make things compile? I know how to compile code that I've written myself but when given a large project containing several CPP and H files, what do I start with? My first port of call, to open 'main.cpp' in Dev-C++ and hit the 'compile' button generally throws up errors about header files not being available and so on.

I won't give a specific example as this has happened several times. I feel as someone getting to grips with C++ that I would learn a lot quicker if I could start with code that works and tweak it myself rather than having to fumble around building things up piece by piece.

The most recent example is a set of example code provided by a company which 10 files:

-Arial.ttf
-demo_resources.rc
-icon.ico
-main.c
-simple.dsp
-simple.dsw
-simple.exe
-simple.h
-trial.c
-trials.c

Running the .exe file works absolutely fine; however if I open main.c and press compile, I receive many error messages. As an example, the first two lines of code in main.c are:

#include "simple.h"
#include <sdl_text_support.h>

This alone spews the error messages:

1: expected unqualified-id before "public"
1: expected `,' or `;' before "public"
2: In file included from trial.c

Clearly I am doing something very wrong as this code must have compiled for someone else in the past to have generated the .exe file. Again this is not an isolated issue, I have this problem all the time.

Since Dev-C++ is perfectly equipped to deal with plain old C files, I can't see that that is the issue. Secondly, simple.h is definitely included in the correct directory. The second include though, sdl_text_support.h is obviously not in my file list above. I have searched the rest of the SDK and found the file lurking elsewhere. How do I explicitly reference the location of the header file using Dev-C++?

Any general tutorial to how to compile pre-made projects or help of any kind would be greatly appreciated.

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

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

发布评论

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

评论(3

維他命╮ 2024-11-12 22:15:53

我不熟悉 DevC++,但你不能假设如果你可以打开 main.c 并按下按钮,那么一切都会成功。没有构建系统那么智能。

如果您编写自己的代码(并且您了解编译和链接),那么您可以保持文件有序并确切地知道如何构建所有内容;别人的代码库可能附带一个 makefile 或其他一些组织指南,但您必须学习如何使用良好的构建系统,而您正在使用的系统听起来还不够。

I am not familiar with DevC++, but you cannot assume that if you can open main.c and press a button, then everything will work out. No build system is that smart.

If you write your own code (and you understand compiling and linking) then you can keep your files in order and know exactly how to build everything; someone else's codebase may come with a makefile or some other guide to it's organization, but you'll have to learn how to use a good build system, and the one you're using sounds inadequate.

蓝礼 2024-11-12 22:15:53

通过 simple.dsw 而不是 main.cpp 打开项目,它应该可以工作。

open the project by simple.dsw instead of main.cpp and it should work .

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