I lately decided to include the JavaScript V8 Engine in my project. After compiling and linking to it, I wanted to run the example from the Getting Started guide.
It works in general, but for some reasons there are namespace conflicts when I do not specify the v8 namespace in front of each class name. Visual Studio 2012 tells me for example, that the name Context would be ambiguous. But I do not understand why.
The only namespaces I include in this file are std and v8. It is a header file and before you ask, it's meant to be so since it claims to be a header-only library.
#pragma once
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <functional>
#include <memory>
#include <typeindex>
#include <iostream>
#include <fstream>
#include <V8/v8.h>
namespace library_name
{
using namespace std;
using namespace v8;
// here comes the example code and more...
}
To find out where a symbol with the name Context might be defined too, I used the Find Definition command in Visual Studio, available in the context menu. This is the list of results.
It lists for example sf::Context which I use in the project but not in that header. There are also definitions in cryptic namespaces located at files in a directory named Windows Kits. I neither know what they are for nor have I included them intentionally. I don't include other header files except from the standard library and JavaScript V8 as shown above.
Why do the Contexts from different namespaces collides with each other? How can I fix this collisions to use the v8 namespace?
Try actually compiling the code. The compiler should list the actual conflicting symbols, possibly including where they are actually defined. You will need to either remove one of your usings or fully qualify the identifier.
Related
These are the two includes which require certain files, libraries for
them to work. Also am using Code Blocks as my IDE.
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time.hpp>
I'm using mongoose to build an HTTP server in C++, and I'm getting an error message when I try to include other files in my program:
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdint:183:8: error:
expected unqualified-id
using::intptr_t;
^
/Users/cs/Downloads/mongoose-master/mongoose.c:2415:18: note:
expanded from
macro 'intptr_t'
#define intptr_t long
^
This happens whenever I attempt include the following files in my program:
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <iterator>
#include <sstream>
I've tried to narrow it down to one of these files causing the problem by commenting out some of them, but it appears that any one of them causes the error. Interestingly enough, string.h does not cause the error.
It sounds like your source code contains something like this:
#include <mongoose.c>
The .c file defines a macro that collides with words used in the standard library headers.
Including a .c file is not a good practice. Instead, you should build the mongoose library, and link your program against it.
If you really have to keep everything in a single translation unit, you should be able to move that dubious include statement to after all other headers, or even to the bottom of your cpp file.
But it would be best to figure out how to build mongoose.c separately, then link against the resulting library. You can ask a separate question, or see if you get anything out of this: Can't figure out how to build C application after adding Mongoose Embedded
I'm including a library in a C++ program, which includes memory and other libraries from the std c++ implementation, like so:
#include <memory>
There is an error happening:
Lexical or Preprocessor issue 'memory' file not found
This happens the same with all the includes in this file:
#include <cmath>
#include <vector>
I'm wondering what could cause such an issue? Could it be that the compiler is not set somewhere properly in the build settings? If so, any idea where?
I am building a header-only library (for good reasons; don't hate) which contains a class and the implementations of the class member functions. In doing so I ran into a very odd error with <unordered_set>. Searches of GCC's Bugzilla turn up nothing that seem to address this.
My code which breaks (badly) has the includes inside my namespace.
namespace probability {
#include <string>
#include <unordered_set> // only this include breaks
#include <unordered_map>
class ProbabilityTools
{
...
By chance, I moved the #includes outside of the class namespace and it fixed the problem with <unordered_set>. None of the other includes caused this problem when placed INSIDE the namespace, only <unordered_set>.
#include <string>
#include <unordered_set> // works when outside the namespace
#include <unordered_map>
namespace probability {
class ProbabilityTools
{
...
I am using GCC g++ 4.8 with -std=c++11 to build this code which works in the second configuration and works as far as <unordered_map> use, in both configurations.
Might this be an libstdc++ bug? GCC bug?
You should not place standard #include directives inside a namespace. See C++14 [using.headers]/3 (which is speaking about the standard library's headers):
A translation unit shall include a header only outside of any external declaration or definition, and shall include the header lexically before the first reference to any of the entities it declares or first defines in that translation unit.
I've created an Allegro 5 project in Xcode 4.6.3 as an empty project. I've added all the Allegro 5 libraries as described in the Allegro documentation. But now I need to use some C/C++ libraries and get the error, that Xcode doesn't find the libraries (e.g. 'fstream file not found').
#include <allegro5/allegro5.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
How can I add the standard libraries to Xcode projects so that it finds them? Unfortunatelly I can't find any solution. This is not an Objective-C Project. It's written in C++ and also works if I don't use any of these libraries.
Thanks!
Does the name of your source file end with an extension that indicates it's C++? If it ends in (for instance) .c or .m, the compiler will not consider it to be C++, therefore the C++ headers won't be found. Try changing the extension on the source file name to .cpp (or some other extension that implies C++, see C++ code file extension? .cc vs .cpp ) and see if the header is found.