7

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.

Anonymous
  • 1,750
  • 3
  • 16
  • 21

3 Answers3

8

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.

Troubadour
  • 13,334
  • 2
  • 38
  • 57
  • The file is being included by proxy through: #include . I have moved this to the very top of the file but I'm still getting these errors. – Anonymous May 25 '10 at 23:19
  • @Anonymous: Is the file that includes mysql++.h a header itself? – Troubadour May 25 '10 at 23:26
  • Yes, but moving it the proper .cpp file still yields the same error. – Anonymous May 25 '10 at 23:30
  • @Anonymous: So if you create a source file with only the line `#include ` in it does it compile? – Troubadour May 25 '10 at 23:32
  • @Anonymous: BTW, when you say you get the same error after moving your header to the top of your source file is it coming from that particular include or is it now coming from another indirect include of cpool.h later on? – Troubadour May 25 '10 at 23:35
  • As I have moved the #include to the source file, the error is now coming from there, again, from within that #include's file mysql++.h which included cpool.h by proxy. – Anonymous May 25 '10 at 23:40
  • @Anonymous: Have you tried to compile a source file with _only_ the line `#include` in it? That works for me on Linux. – Troubadour May 25 '10 at 23:51
  • Compiling a new source file with just that one line yields the same error. – Anonymous May 25 '10 at 23:56
  • @Anonymous: OK, I give up :) Sounds like the bug is genuinely in the version of MySQL++ you got from Macports. – Troubadour May 25 '10 at 23:59
8

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

#include <cassert>
MBI
  • 583
  • 8
  • 22
3

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.

Greg Prisament
  • 2,166
  • 1
  • 17
  • 18