Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"'assert’ was not declared in this scope" in MySQL++

I'm compiling a project in XCode where MySQL++ in included and linked to. For some reason, I keep getting the following compiler error:

'assert’ was not declared in this scope

originating from cpool.h, a header file that's part of MySQL++. Does anyone know why this is being triggered?

EDIT: For reference, MySQL++ was installed via Macports.

like image 417
Anonymous Avatar asked May 25 '10 22:05

Anonymous


3 Answers

The most obvious answer would be that "assert.h" is not being included or is not being found in your include path. Another explanation is that the assert macro has been undefined at some point after the header was included.

Edit: Since you say that assert.h is included, and we'll assume for the moment that it's being found since it's a standard header, then that leaves us with the last possibility I stated above i.e. that the macro has been undefined.

Since cpool.h itself will not be doing this it must be the case that assert.h is included earlier either by yourself or indirectly by another 3rd party header and the undefining happening between this and your inclusion of cpool.h. This can easily be tested by moving your cpool.h include to the top of your file.

like image 104
Troubadour Avatar answered Oct 14 '22 18:10

Troubadour


In c++ adding cassert header should fix your problem.

#include <cassert>
like image 35
MBI Avatar answered Oct 14 '22 16:10

MBI


It could be that another library in your include path has a different "assert.h" file, and you are unknowingly including that one instead of the system's standard <assert.h>.

I ran into this issue when writing an application that uses gstreamer on Mac OSX. It turns out that gstreamer's include directory (/Library/Frameworks/GStreamer.framework/Headers) includes a file "assert.h", which is non-standard and an unsuitable replacement for the real assert.h. When I added -I/Library/Frameworks/GStreamer.frameworks/Headers to my compilation command, suddenly my sources, which just said "#include <assert.h>" where including the gstreamer version. This caused my compilation to fail with the same error you were getting.

like image 30
Greg Prisament Avatar answered Oct 14 '22 18:10

Greg Prisament