How to find comiler-error?
Hello!
I have a large project. I have done some changes in some files, and obviously I did something wrong: When comilig the project, I get an error in a (correct!) header file:
void STDCALL mysql_close(MYSQL *sock);
int STDCALL mysql_select_db(MYSQL *mysql, const char *db);
int STDCALL mysql_query(MYSQL *mysql, const char *q); <-- Error
int STDCALL mysql_send_query(MYSQL *mysql, const char *q,
The compiler says:
include\mysql.h(243) : error C2143: syntax error : missing ')' before 'constant'
\include\mysql.h(243) : error C2143: syntax error : missing ';' before 'constant'
\include\mysql.h(243) : fatal error C1004: unexpected end of file found
... which is obviously wrong. My problem is: How can I find the real error?
Martin
[845 byte] By [
martho] at [2007-11-17 22:39:41]

# 1 Re: How to find comiler-error?
Are these the only errors you get or are there other errors preceding them?
# 2 Re: How to find comiler-error?
The strange things is that these are the only errors/warnings I get. The header-file is include in almost every file of my project.
martho at 2007-11-10 8:42:44 >

# 3 Re: How to find comiler-error?
I hate errors like this - they're always the most difficult to find. Try looking for a file which #includes your (correct) header file and you'll probably find the error just before the relevant #include. Now here's the problem... The relevant line will probably be another #include, in which case your problem lies in a different header file.
Also, errors like "Unexpected end of file found" are often caused by redefining macros and not getting the number of brackets right. e.g. #define something(a) { a = 2; might give that error because you've missed off a closing bracket (that's not a great example, but you get the idea). Similarly, #define something(a) { a = 2 } will throw up errors in odd places because you missed the semicolon. In fact, if you changed any code in brackets (braces) check that you didn't accidentally delete one.
When you're modifying unfamiliar code (particularly other people's code) it's always a good idea to keep a copy of the original files so you can selectively replace them if you hit this type of problem. Better yet, get yourself a copy of Code Co-op, which is invaluable in situations like this.
One final idea. If the header file is #included by most of your source files, try compiling the source files individually with [CTRL] + F7. It may or may not help, but it's worth trying.
John E at 2007-11-10 8:43:43 >

# 4 Re: How to find comiler-error?
Originally posted by martho
The compiler says:
include\mysql.h(243) : error C2143: syntax error : missing ')' before 'constant'
\include\mysql.h(243) : error C2143: syntax error : missing ';' before 'constant'
\include\mysql.h(243) : fatal error C1004: unexpected end of file found
... which is obviously wrong. My problem is: How can I find the real error?
Take a look at the definitions in 'mysql.h'. There might be only a ';' missing somwhere...like
class CFoo
{
...
}; // <-- If this ';' is missing you will get this kind of error
class CFoo2
{
};
Another possibility would be the type 'MYSQL'. I assume this is a class. If you have something like this
int Func(CFoo *pFoo)
{
return pFoo->Whatever();
}
class CFoo
{
public
int Whatever();
};
the compiler will complain that it does not know the class while compiling the function since it is defined after the function. In this case a forward declaration would help...
class CFoo;
int Func(CFoo *pFoo)
{
return pFoo->Whatever();
}
class CFoo
{
public
int Whatever();
};
If these common pitfalls are not the cause in your application you might need to provide more information. The compiler prints out the name of the .cpp file while compiling it. That should you give a hint which implementation causes it...
# 5 Re: How to find comiler-error?
Originally posted by martho
The strange things is that these are the only errors/warnings I get. The header-file is include in almost every file of my project. Do you get the errors when compiling each file the include is used in?
If I understand what you are saying then the error is occuring in a line that is at least the third line of th include. If so then that indicates to me that the problem is not with code that (physically) precedes the include.
What is mysql_query? Is it a function or a macro? If it is a function then did you perhaps make a macro with that name?
# 6 Re: How to find comiler-error?
(My favourite hobby horse) Try setting "Using Precompiled Headers" off, and re-compiling the whole project. I've found that the message about "unexpected end of file" is often caused by a problem in a pre-compiled header.
TSYS at 2007-11-10 8:46:44 >

# 7 Re: How to find comiler-error?
Well if you typed in your code the was it is in your program, take alook at your last function declaration. It ends wit a commayou are probably missing some of your declaration with the closing parenthises and semi-colon.
# 8 Re: How to find comiler-error?
Thanx for all the replys.
Sam: The mysql.h-file itself is fine. It's a header-file shipped with MYSQL, I downloaded it once more with (unfortunatly) no effect.
John got the right point: The file is include in a file which is included which is included... But the file is always included first, so strange enough the error still occurs.
At last I restored a backup and tried to redo the changes I did after making the backup. Now it works. Thanx anyway for all the hints!
martho at 2007-11-10 8:48:47 >

# 9 Re: How to find comiler-error?
Originally posted by martho
John got the right point: The file is include in a file which is included which is included... But the file is always included first, so strange enough the error still occurs.So is that what caused the error? As best as I understand what you are saying we do not know what the problem was so I don't understand why it is relevant that the include was embedded. I think the main reason that was not mentioned more than it was is that it probably was not relevant.
# 10 Re: How to find comiler-error?
Hi Sam,
first I tried to find the error by looking which file is including which, but I could not find any problems there (after some times counting brackets is not very interesting ;) )
Then I tried to find out what caused the error by overwriting the actual version file-by-file with the backup. But since it is a large project, I did this only with the files I thought I changed since the last backup or files, which I thought could produce the error - with no success. So after some point I just gave up for time-reasons (after replacing a file you have to compile the whole project). Then I just copied all the files back - and it worked.
I have made a copy of the "corrupted" version, so if I have some time I will search the error again - perhaps with Windiff or some tool like that. Just being curious for myself. If I find it I will post it here.
martho at 2007-11-10 8:50:57 >

# 11 Re: How to find comiler-error?
That is all understandable and reasonable. Certainly we all want to know what the problem was but I understand and I assume everyone understands that it is not always possible to determine the problem.