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

create a header-only version #16

Closed
nlohmann opened this issue Jan 6, 2015 · 17 comments
Closed

create a header-only version #16

nlohmann opened this issue Jan 6, 2015 · 17 comments

Comments

@nlohmann
Copy link
Owner

nlohmann commented Jan 6, 2015

As wished in http://www.reddit.com/r/cpp/comments/2rbhn3/json_for_modern_c_what_if_json_was_part_of_modern/cnelnzq:

I think this would be fare more useful as a header only library. I'm down for sending a PR with the change if you are.

And as I wrote:

Good idea! But I think it would be more useful if there would be a script that reads the source files json.cc and json.h and creates a header-only version. That way, both approaches can be followed at the same time.

@hrobeers
Copy link

hrobeers commented Jan 6, 2015

Or people can just include the cpp file.
I don't really see the advantage of making it header only.

@PaulFreund
Copy link

It can improve compile time when precompiled headers are used and allows easy include only usage. The cpp file always has to be supplied to the compiler (which is mostly done by build tools that assume everything in one root) and therefore encourages adding the source directly in projects instead of just pulling them from a central include path.

Unfortunatly the cpp world has no ultimate solution to dependencies, packaging, etc. so I don't know if this is an advantage for others.

@daminetreg
Copy link

Have you already seen biicode ? They are really active in bringing a dependency solution for C++.

@PaulFreund
Copy link

I've seen it and it seems pretty cool, but I don't want to rely on proprietary tools. I couldn't find a statement about escrow or plans for worst case.

@nlohmann
Copy link
Owner Author

nlohmann commented Jan 9, 2015

@PaulFreund - could you check if the file header_only/json.h suits your needs?

@Teemperor
Copy link
Contributor

Should we really push the generated header only version to the repository? It's a generated file similar to a binary and should be hosted somewhere else.

@nlohmann
Copy link
Owner Author

nlohmann commented Jan 9, 2015

I thought about it and thought the way Catch are doing it is reasonable. In the end, creating the header requires tools such as cat and sed. While they may be standard on some machines, they are not for Windows. Once the code is reasonably stable, one could think about using GitHub's release feature.

@Teemperor, what do you think?

@Teemperor
Copy link
Contributor

I think a release on Github from time to time is the best solution right now. It's just slightly more work compared to pushing the header file to git and it keeps the repository clean.

If we want this automated, we could also just run the header generation on a external server and serve it over HTTPS (or use the Github API to create releases).

@nlohmann
Copy link
Owner Author

Apart from the issue of how to publish the header-only version, I think we are done here.

@PaulFreund
Copy link

Sorry for the late reply. Unfortunately just copying header and source together won't be enough. While free functions could be inlined, the member functions that are defined outside of their class declarations can't.

From my point of view there are only upsides for developing the library completely header only but I understand that it might also be a matter of taste.

@nlohmann
Copy link
Owner Author

Thanks @PaulFreund for your reply.

As I have no experience in creating a header-only version, I assumed that copying the sources would be enough. Can you give me more insights why this is not sufficient or point me to sources that explain how to do this properly?

@nlohmann nlohmann reopened this Jan 11, 2015
@Zoadian
Copy link

Zoadian commented Jan 16, 2015

you'll get duplicated symbols if you include it more than once

@nlohmann
Copy link
Owner Author

You are right. I did not check for a case where the header is included in several files. :-(

@danpolanco
Copy link

👍 for header only version.

@cdaylward
Copy link

👍 for header-only version. I'm very happy with this library but I had to do my own temporary patching (inlining) so that I could use it in my own header-only libraries.

@nlohmann
Copy link
Owner Author

Fixed in latest commit: the class is now header-only.

@danpolanco
Copy link

👏

@Hoohya Hoohya mentioned this issue Jan 2, 2020
GerHobbelt pushed a commit to GerHobbelt/nlohmann-json that referenced this issue May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants