尝试研究 Shine MPEG Layer-III 编码器 - 获得“C++的重新声明”内置类型“bool”
问候。
我正在为即将到来的项目研究 mpeg 第三层编码的工作方式。我下载了 Shine 编码器,因为据说它是最简单的。 http://www.mp3-tech.org/programmer/sources/shine.zip 是链接。
我在一个独立项目中成功编译了它们,但我需要在 QT 项目中使用它们。
我在 QT 中创建了新的空白控制台项目 并将之前为我成功编译的所有文件添加为现有文件(来自 Shine.zip 的文件)。
这是我的 main.cpp:
#include <QtCore/QCoreApplication>
#include "main.h"
int main(int argc, char *argv[])
{
// QCoreApplication a(argc, argv);
// return a.exec();
mainc(argc,argv);
}
这是 main.h:
#ifndef MAIN_H
#define MAIN_H
#include "main.c"
#endif // MAIN_H
其他一切都未受影响(我的意思是,没有这两个文件,它编译成功并工作)
我现在在这部分遇到错误
#ifndef bool
typedef unsigned char bool; <--- "redeclaration of C++ built-in type 'bool'"
#endif
之前这里没有错误。据我了解,一个 cpp 文件的存在会使所有代码编译为 c++,而闪耀代码是 c,而不是 c++...这是否意味着我不能在使用 QT 类 QCoreApplication 的项目中使用 c 代码?
Greetings.
I am studying the way mpeg layer-III encoding works for an upcoming project. I downloaded the shine encoder as it is said to be the simpliest of all. http://www.mp3-tech.org/programmer/sources/shine.zip is the link.
I successfully compiled them in a standalone project but i need to be using them in a QT project.
I made new blank console project in QT
and added as existing all the files that previously successfully compiled for me (files from shine.zip).
This is my main.cpp:
#include <QtCore/QCoreApplication>
#include "main.h"
int main(int argc, char *argv[])
{
// QCoreApplication a(argc, argv);
// return a.exec();
mainc(argc,argv);
}
This is main.h:
#ifndef MAIN_H
#define MAIN_H
#include "main.c"
#endif // MAIN_H
everything else is untouched (i mean, without those two files it compiled successfully and worked)
I am now getting error at this part
#ifndef bool
typedef unsigned char bool; <--- "redeclaration of C++ built-in type 'bool'"
#endif
Before there was no error here. From what i understand a presence of one cpp file makes all the code compile as c++ and the shine code is c, not c++... Does it mean i cannot use c code in a project that uses QT classes QCoreApplication?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在同一个项目中混合 C 和 C++ 代码,但需要使用 C 编译器来编译 C 代码。不要尝试从 C++ 文件中包含
main.c
,而是单独编译 C 代码,并将需要从 C++ 调用的任何 C 函数声明为extern "C"
,例如You can mix C and C++ code in the same project, but you need to compile the C code with a C compiler. Rather than trying to include
main.c
from a C++ file, compile the C code separately, and declare any C functions you need to call from C++ asextern "C"
, for example切勿将实现文件包含在头文件中。这
是错误的。如果
#ifdef MAIN_H
不提供保护,则会导致包含递归。在您的示例中,
QCoreAppplication
包含两次导致错误消息的内容。Never include the implemenation file in the header file. The
is wrong. It would lead to an include recursion, if the
#ifdef MAIN_H
would not protect.In your example
QCoreAppplication
is included twice what leads to the error message.