views:

34

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.

My current step that i FAIL at is to compile the source codes i downloaded.

I never before worked on a lower levels of programming or compiling, to say, i mostly worked in GUI's and just made projects, designed forms, written code... I do understand basically how compiling and linking works but i never did it from command line or anything. Also i cannot say i am very skilled with c/c++ as i developed for Borland Delphi and then went straight to .NET with C#. I assume that since files are called .h and .c they are C, not C++ files.

I was told to use QT Creator since the upcoming project will have to run on Linux as well, and our company uses QT for making Linux apps.

I did create a blank QT creator console application project, but unlike c, this console appicaton contains event loop (???). Anyways, what i did is removed main.cpp and added all shine project files. I made main.c file the first one in SOURCES list so compiling starts with it.

Now, the compiler tells me this common error

"expected '=', ',', ';', 'asm' or '__attribute__' before"

for example, at lines:

bool  wave_open(); 

at wave.h

and

static bool parse_command(int argc, char** argv) 

at main.c

I didnt find any description of this error, all cases of its discussion on the webs lead to persons finding typos in another files that leads to the error (forgetting a letter or # before endif in previous header file). I dont understand what is this error about as for example, adding

int i;

before the error still makes compiler spit this same error again.

Could someone please suggest what do i need to do to actually compile the code under QT Creator?

A: 

Looks like bool is not defined. Include stdbool.h

Amarghosh
Just add a `typedef int bool;` before the line that gives this error to confirm that `bool` indeed is the issue. If it is, remove the typedef, add `#inculde <stdbool.h>` (or any other qt specific types header file that defines bool). With respect to how it was defined in some places and not some other places, its hard to say anything without seeing more code.
Amarghosh
I see now. In types.h, it had #ifndef booltypedef unsigned char bool;#endifand it complained about redeclaring bool which is c++ type so i had to comment it. Now i uncommented it and its working all right.
Istrebitel
Okay,then, what do i do if i want to use QT's features? I mean, previously, i had main.cpp file that was including main.c file and i renamed main.c "main" to "mainc" and called mainc from main in main.cpp, which leaded to that "redeclaration of bool" problem. Now i removed main.cpp from project, made main.c the first file and it compiles fine. But if i want to, say, add QT gui to it, what do i do? How do i fix the problem of C not knowing about bool but c++ forbidding me to define it?
Istrebitel
Don't include a `.c` file in another file - include `.h` files in c and cpp files. Are you compiling it as c or cpp?
Amarghosh
So i should do like this: - starting from new blank console project in QT- add main.h, include it from main.cpp- in main.h, include main.c- run mainc(former main or main.c) from main.cpp's main?
Istrebitel
sorry this form does not allow line breaks and has very little char limit so i will reply in an "answer". I did got it to compile and work but my goal is to incorporate the code into my QT project. For that i did as i stated before and this leads to new errors.
Istrebitel
I'm not sure what you're trying to achieve by including `main.c` in `main.h` - the question has changed considerably from its initial form, which was about the undefined bool part. I say you either edit the question or ask a new question on how to compile and run the downloaded qt code, citing the issues you're facing. You can't have newlines in comments - you can edit your question and add information to it though.
Amarghosh
okay sorry i'll make a new question then
Istrebitel
by including main.c in main.h i am trying to achieve to be able to use functions from main.c in my QT program. What i am trying to achieve is to test if i can use the code that encodes an mp3 from the shine encoder in QT application. Here is the new question link http://stackoverflow.com/questions/3959783/trying-to-study-shine-mpeg-layer-iii-encoder-getting-redeclaration-of-c-buil
Istrebitel
A: 

I made new blank console project in QT and added as existing all the files that previously successfully compiled for me

Okay, 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
Istrebitel