views:

55

answers:

2

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?

A: 

Never include the implemenation file in the header file. The

#include "main.c"

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.

harper
Thank you, i've read about header files now and i understand i was wrong with that one. So, if i get it right, when i include a .h file, compiler will automatically look in same name .c or .cpp file for code?
Istrebitel
+1  A: 

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++ as extern "C", for example

extern "C" int mainc(int argc, char *argv[]);
Mike Seymour
Thank you! Okay i see, so, what i should have done, is make a header file which i include in my main.cpp file, this header file should do this declaration and then file with the same name as this header .c should contain implementation, right? I mean, now its working for me, but i cant be sure i did it right...
Istrebitel
@Istrebite: yes, that sounds right.
Mike Seymour