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.
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.
In c++ adding cassert header should fix your problem.
#include <cassert>
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.
Related
I'm in VS2013, C++ console applications. I'm having a problem integrating boost into a large framework. If I try integrating them in a blank console application, they work fine. Once I include the "root" .h file of the framework (that includes "many" other .h files in the bargain), it breaks. These .h files are "polluting" the boost ones (and anything included after, with mixed results, and no, I can't just include boost ones first, that's not always an option unfortunately). I've found at least one root-level #define that interfered and caused a compile error, but I can't find some of the other conflicts that are causing run-time problems.
Specifically, my problem is this: how do I tell what symbols have been defined by .h files? And hopefully, which ones are then conflicting later? I tried googling, but couldn't find a tool for doing this.
Or is there some other method which can "isolate" them (my problem .h files), and yet still have them link correctly to the functions they're calling in other .dlls?
You can use g++ -E as a static code checking tool (without changing your toolset). It is able to tell you when something is redefined but not when a #define is used as another name (it would have no way to tell whether it was a real substitution or not).
If that's not the source of your problem then you may need to take a more holistic approach: Start changing your project's #define use to other constructs such as const and short functions. This will then allow the compiler to either resolve differences by overloading or complain that there are conflicts.
Including same header file again might have caused the problem,you can create a symbol for each header file so that if that header file is already included in some other header file it shouldn't be included.
#ifndef
#define __header_file_name_H
.....some code
#endif
I'm currently stuck on a compilation problem on Android for my app.
I get the following error during the compilation of my native library with ndk-build:
BackgroundDisplayConfiguration.h:12:23: fatal error: glm/glm.hpp:
No such file or directory
#include <glm/glm.hpp>
^
What puzzles me is that I have specified a path for this header only library in my Android.mk the following way:
LOCAL_CPPFLAGS += -I../../glm/include
and this path exists and is correct, but moreover if I mess up this path I get the same error in other files that include glm.hpp. When the path is correct, only this file yields an error, and I don't understand why. Any pointers?
EDIT: Okay, this is even more puzzling. The include option appear in every compiler command for each file, but not on the compiler command for the big wrapper generated by swig (that outputs my library_native_wrap.o), and that's where it yields an error... Well, it at least explains the observed behavior.
So I found a workaround for this, even though it doesn't feel quite right.
Indeed, I found out that when compiling every source of my library, the compiler command actually had the include option, but then, when compiling the output of swig (that big unique c++ wrapper file), the option wasn't there anymore.
I found a way to correct this by adding my include path to the LOCAL_EXPORT_C_INCLUDES.
For some reason, the LOCAL_CPPFLAGS aren't used when compiling the wrapper...
I'm trying to have Cmake check if the file cxxabi.h is available. This file is from the c++ standard library, at least with g++. My current cmake commands look like this:
include(CheckIncludeFiles)
...
check_include_files(cxxabi.h HAVE_CXXABI)
if(HAVE_CXXABI)
...
else(HAVE_CXXABI)
...
endif(HAVE_CXXABI)
When this is executed, I get:
-- Looking for include files HAVE_CXXABI
-- Looking for include files HAVE_CXXABI - not found.
Although the file is available in /usr/include/c++/4.6.4/ and can properly be found by g++ when I compile a c++ code.
I suspect the macro check_include_files uses the C compiler instead of the C++ one to compile a small program that includes the required file, which of course fails since cxxabi.h is a C++ file.
Any idea how to solve that? (i.e. making the macro use the C++ compiler instead of the C one)
As edited in my original question:
Problem solved. There is a different macro for C++ headers, check_include_file_cxx, located in CheckIncludeFileCXX.
There exists another problem with CHECK_INCLUDE_FILES that I recently discovered with MinGW. The file tested was "ddk/ntapi.h". In the CMakeErr.log for this header I got a multiply messages like "DWORD - does not name a type" and so on for all MS types used in this header. Because of this reason the compilation fails and a requested header appears as "not found", whereas it is not true.
This happens because CheckIncludeFile.cxx contains only the requested header, and some headers in MinGW (and probably in the other APIs) does not include in its body all the list of required headers to be compiled in a standalone program that CMake creates.
The solution for this problem is to add absent basic includes into the CMAKE_REQURED_FLAGS, or as a third variable of CHECK_INCLUDE_FILE_CXX:
CHECK_INCLUDE_FILE_CXX("ddk/ntapi.h" VAR "-include windows.h")
I am very new to c++ and am doing a tutorial. I have copied the tutorial exactly but on compiling get this error:
'String file not found'
for the line #include <string>;
Could someone tell me how to amend this?
Ok, so I changed the name of my file from .C to .cpp and this particular issue seems to have gone.
You seem to have found a solution, I'm adding this to clarify why this is happening. Some compilers integrated with IDEs treat .c files as C source code an .cpp (or .cc, .c++, etc.) as C++ code. As you compile a .c file, C++ support isn't included and a C compiler is used instead of a C++ one. And C doesn't have <string> (although it does have <string.h>, but that contains entirely different stuff).
It looks like your compiler isn't correctly or fully installed. The compiler should be able to find its own headers without further effort on your part.
Ok, so I changed the name of my file from .C to .cpp and this particular issue seems to have gone. However, I now get 3 Apple Mach-o Linker (Id) errors (?)
As this is different to the original questions I will close this and open a new one
Thanks for all the help!
check the location c:/...../include
If exist string file should reinstall compiler
I just wrote a simple C++ program in Visual Studio 2010 and I use ceil function. But I forgot to include the <cmath> and only included the <iostream>. Surprisingly my code compiled successfully and ran without any error. I read a C++ book and it clearly says that to use ceil function you must include <cmath> or <math.h>. Why this happens? Can anyone explain me? Thanks!
The header is indirectly included from some other (indirectly) included header.
To find out which one, enable 'keep preprocessed source' (/P) from the project options and inspect the resulting (*.i) file
Update Just found out that VS2010 has renamed the related option:
Technically speaking, implementations are allowed to automatically include any header in the system headers. But this is implementation defined.
In some cases, <cmath> is already included, in other cases, it isn't - same applies to all the other standard headers.
This issue came up on this question: https://stackoverflow.com/questions/7632926/is-this-a-c-program-or-c-program-how-to-decide
That aside, it's possible that it could be indirectly included by other includes.