I am trying to use nlohmann json in my C++ project. I extracted the zipped file after I downloaded it from github. I renamed the extracted folder to be nlohmann_json and just copied it inside my project .
The github doc says :
json.hpp is the single required file in single_include/nlohmann or released here. You need to add
#include <nlohmann/json.hpp>
// for convenience
using json = nlohmann::json;
So in my .cpp file, I have the following lines :
#include "nlohmann_json/include/nlohmann/json.hpp"
using json = nlohmann::json;
But Visual Studio 2015 IDE shows as tooltip the following message:
namespace nlohmann has no member json
After typing just nlohmann:: , I get an auto suggestion of json_pointer but not json.
What is going wrong actually ?
You actually have a hint to your problem.
json.hpp is the single required file in single_include/nlohmann or released here. You need to add
If you go to the original tree you checked out from github, and do this:
$ find . -name json.hpp
./include/nlohmann/json.hpp
./single_include/nlohmann/json.hpp
You might see your problem. You're including the first of the found files. You really need the second one -OR- you need to set up includes search path better.
Here's what I would do. I would copy ./single_include/nlohmann/json.hpp into the project. I would NOT include the entire tree, just that file. And include it.
I think that will work better for you.
You can either use the single header approach where you can directly include the single json.hpp (inside the single_include, just drop nlohmann/json.hpp at the root of your project). Or if you want to include the one that have multiple files then you will need to set additional include headers in your VS project settings.
MyProj
nlohmann\....
main.cpp
Then in your VS project settings add the path to your project to the additional include directories.
Related
I just started using VSCode on linux Ubuntu environment and for past one day trying to include some header files from a sub-Directory (the project screen shot is shown below).
I have tired adding the header file path in include path but showing error.(Image below)
I also tired by provided complete path e.g. /home/user/Work/Cpp_Test_Project/OpenFace/FaceAnalyser/include/ still it couldn't find the header file.
Also, If I try to include the header with local path e.g.
#include <OpenFace/LandmarkDetector/LandmarkCoreIncludes.h
then all the internally linked header file doesn't work.
any help will be highly appreciated.
The c_cpp_properties.json file is for configuring IntelliSense. The compiler you are using does not read from this file, so you will need to configure the include path for that separately. From what you have posted, it is unclear how you have set up your build.
I'm trying to build opencv2 as a universal framework. I am systematically removing the files/folders that I do not need. But I am running into this issue where the include files are not found. See the image below:
The following image clearly shows that the file is indeed there.
One of the contractors working with us said he had put the include files into the same directory as the source files and rename them according to their file structure but using "." instead of "/" as shown below:
But that means that I must go through all of the files that include files and change the include statement to use "." instead of "/". REALLY?
Is this true? Or do we have a configuration set wrong?
You need to setup search paths for your target in Build Settings->Search Paths->Header search paths.
I'm pretty new to C++ and Eclipse in general so I apologise if I'm missing something fairly obvious.
The problem I'm having is that I'm trying to include a header file in one of my source files but they're in different folders in my project directory. I have no idea how I should be including them. I've uploaded an image showing my problem with the header file I want to include highlighted.
If someone could tell me what '#include' statement I should be using them that would be brilliant.
Thanks!
There are a couple of different options to make this work. Simplest is to change the #include to
#include "../Statistics/Statistics.h"
This will work without any other modifications. However, if you move either file, or somehow change the relative path between the two, this will break.
Alternately, you can add the path to the Statistics folder to your compiler's include file search path. Right click on the project name, select Properties -> C/C++ Build -> Settings and then find the includes files path option for your compiler. For g++, it is -I<path/to/include/folder>. Adding this will make the #include statement work as you currently have it.
A very similar option to the second one is to add the path to the src folder (instead of the Statistics folder) to the includes search path. In this case, you'll have to change the statement to
#include "Statistics/Statistics.h"
When you create subfolders in your src folder then each cpp file is compiled in that folder it is located in. Thus, any "" includes need to specify the relative path to get from that folder to another.
In your case, to get from inside the FileInOut folder you need to go back one level and then into the Statistics folder
eg
#include "../Statistics/Statistics.h"
Another alternative is, if you are keeping your includes in your src directory, to add the src directory to the include path. Now when you include you need only specify the path from the src root.
eg.
#include "Statistics/Statistics.h"
http://youtu.be/6NCtnKcwOas (select better quality!)
As you can see on the attached video, I have the two projects in my solution - a dll creator and a simple testing project. Just followed this tutorial .
Why does the MathFuncsDll.h still remain undetected?Everything works fine after specifying the full path after '#include'. However, I don't want to use such rough-and-ready method because it looks messy and unprofessionally.
If you can specify the file using an absolute path, but not by only using its filename, the compiler doesn't "know" about the folder containing that file.
You can tell the compiler about your additional include directories via the /I directive (documentation). And of course you can set that via the IDE.
I'm running into an import issue that as a relative newcomer to the Objective-C/C++/XCode world I haven't seen before.
I'd like to include this library with my project: https://github.com/jdkoftinoff/jdksmidi
But, it seems like no matter how I try to add it to the project, I get errors when I try to import:
#import "jdksmidi/world.h"
(No such file or directory)
I can import without the jdksmidi subdirectory, but since inside all of the headers included with the library, the author uses the same syntax with the subdirectory, I'm stuck.
Simplified question: how do I add the library to my project so that I can use the #import "jdksmidi/___FILE____.h" format and not throw compiler errors?
Thanks
You probably need to adjust your User Header Search Paths (USER_HEADER_SEARCH_PATHS) in your build settings. Make sure that the folder containing jdksmidi is in the path. Hope that helps.
you need add your jdksmidi/world.h file in project, just drag'n'drop it into your groups & files section. Or you can use #include directive