Hi,
I would like to create hello world json example with gcc on Raspberry.
I have runned 'make' but I do not see install option.
How can I install/use it on RPI?
You can use it with CMake
$ mkdir build && cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/place/to/install/it
$ make -j 4 install
@xsacha The library itself contains of a single header in single_include. You do not need to install it - it is sufficient to copy the json.hpp file wherever you put your include files.
@nlohmann Can't say I've ever done that (copy the file).
I have started @xsacha variant but I had to terminate, it takes too long.
Later I will start it again. At the end it should be installed to ie. /usr/local/include as json.a or?
I have downloaded the single_include json.hpp
I tried so:
hello.cpp
#include <iostream>
#include <json>
int main()
{
cout << "Hello World!" << endl;
return 0;
}
hpp file is saved to same dir:
hello.cpp json.hpp
tried to run following command:
g++ hello.cpp -o hello -I.
I got
hello.cpp:2:16: fatal error: json: No such file or directory
#include <json>
^
compilation terminated.
If the json.hpp header is in the same directory, you can use
#include "json.hpp"
The result of the installation will not be a static or dynamic library, but just a C++ header. As the library uses templates, you cannot precompile it.
yes I can use "" thanks.
I have changed it.
But now I got lot of errors:
g++ hello.cpp -o hello
In file included from /usr/include/c++/4.9/initializer_list:36:0,
from json.hpp:42,
from hello.cpp:2:
/usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support for the \
^
In file included from hello.cpp:2:0:
json.hpp:92:36: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
std::size_t chars_read_total = 0;
^
json.hpp:94:43: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
std::size_t chars_read_current_line = 0;
^
json.hpp:96:30: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
std::size_t lines_read = 0;
^
json.hpp:99:5: error: Γ’constexprΓ’ does not name a type
constexpr operator size_t() const
..
With the make I should get the same json.hpp under -DCMAKE_INSTALL_PREFIX=/place/to/install/it as yours?
I am testing with g++ hello.cpp -o hello -std=c++11
Yes, you need to use -std=c++11.
It works :) thanks for the nice lib!
just one thing:
When I run the make I should get the same json.hpp under -DCMAKE_INSTALL_PREFIX=/place/to/install/it as yours?
If you're using the single header you don't need CMake or to install it.
When you call make install, all it does is compile the unit tests (which you can switch off by -DBUILD_TESTING=Off) and create the following structure in the directory you pass via -DCMAKE_INSTALL_PREFIX:
βββ include
βΒ Β βββ nlohmann
βΒ Β βββ json.hpp
βββ lib
βββ cmake
βββ nlohmann_json
βββ nlohmann_jsonConfig.cmake
βββ nlohmann_jsonConfigVersion.cmake
βββ nlohmann_jsonTargets.cmake
You do not need the files in lib, unless you do more with CMake. File include/nlohmann/json.hpp is the same as single_include/nlohmann/json.hpp from the repository.
@kuzmanzs Do you need further assistance in this issue?
@nlohmann : everything is working fine, thanks.
Most helpful comment
You can use it with CMake
$ mkdir build && cd build
$ cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/place/to/install/it
$ make -j 4 install