Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use it from gcc on RPI #1528

Closed
kuzmanzs opened this issue Mar 20, 2019 · 13 comments
Closed

How can I use it from gcc on RPI #1528

kuzmanzs opened this issue Mar 20, 2019 · 13 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@kuzmanzs
Copy link

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?

@xsacha
Copy link

xsacha commented Mar 20, 2019

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

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Mar 20, 2019
@nlohmann
Copy link
Owner

@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.

@xsacha
Copy link

xsacha commented Mar 21, 2019

@nlohmann Can't say I've ever done that (copy the file).

@kuzmanzs
Copy link
Author

kuzmanzs commented Mar 21, 2019

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.

@nlohmann
Copy link
Owner

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.

@kuzmanzs
Copy link
Author

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?

@kuzmanzs
Copy link
Author

I am testing with g++ hello.cpp -o hello -std=c++11

@nlohmann
Copy link
Owner

Yes, you need to use -std=c++11.

@kuzmanzs
Copy link
Author

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?

@xsacha
Copy link

xsacha commented Mar 21, 2019

If you're using the single header you don't need CMake or to install it.

@nlohmann
Copy link
Owner

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.

@nlohmann
Copy link
Owner

@kuzmanzs Do you need further assistance in this issue?

@kuzmanzs
Copy link
Author

@nlohmann : everything is working fine, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants