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

Fixes for compiling with a newer (system) jsoncpp #4429

Merged
merged 3 commits into from
Aug 10, 2016
Merged

Conversation

Rogier-5
Copy link
Contributor

See issue #4306.

The primary problem turns out to be that minetest uses #include "json/json.h", where it should use #include <json/json.h>.

Another problem which surfaces then, is that jsoncpp contains a bug, which makes it fail to compile in non-c++11 mode. The following change is neede to /usr/include/jsoncpp/json/config.h, to make it compile.

Change:

#if defined(_MSC_VER) && _MSC_VER <= 1600 // MSVC <= 2010
# define JSONCPP_OVERRIDE
#else
# define JSONCPP_OVERRIDE override
#endif // MSVC <= 2010

To:

#if __cplusplus < 201103L
# define JSONCPP_OVERRIDE
#else
# define JSONCPP_OVERRIDE override
#endif // __cplusplus < 201103L

Jsoncpp's config.h contains other similar code (similar to #if defined(_MSC_VER) && _MSC_VER <= 1600 // MSVC <= 2010), and I haven't assessed whether that should be changed as well. With the jsoncpp patch above, minetest compiles, and the server starts and seems to work fine. I couldn't test the client.

This is needed to avoid having to specify the minetest src directory
as a system include when fixing the json includes.
They used "", so that the compiler searches the project's directory
first. The result was that when compiling with a system jsoncpp,
the project's own version of json.h was still included, instead of
the system version.

The includes now use <>, so a system location, or one specified with
'-Ilocation' is searched only.
@@ -1250,8 +1250,13 @@ static bool push_json_value_helper(lua_State *L, const Json::Value &value,
lua_newtable(L);
for (Json::Value::const_iterator it = value.begin();
it != value.end(); ++it) {
#ifndef JSONCPP_STRING
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put these entirely to the right?

When compiling with a newer version of jsoncpp (and
ENABLE_SYSTEM_JSONCPP=true), jsoncpp emits a warning
about a deprecated function that minetest uses.
@est31
Copy link
Contributor

est31 commented Aug 10, 2016

👍

@est31 est31 added @ Build CMake, build scripts, official builds, compiler and linker errors Bugfix 🐛 PRs that fix a bug labels Aug 10, 2016
@nerzhul
Copy link
Member

nerzhul commented Aug 10, 2016

👍

@est31 est31 merged commit 4503b50 into minetest:master Aug 10, 2016
@Rogier-5 Rogier-5 deleted the json branch August 10, 2016 10:12
@ghost
Copy link

ghost commented Aug 17, 2016

Using Arch with gcc 5, I was unable to compile for android, many instances of unable to find json/json.h. I manually backed out the subdirectory changes and was then able to compile successfully.

@Rogier-5
Copy link
Contributor Author

@zing269 This sounds like you compiled with ENABLE_SYSTEM_JSONCPP set to true (or 1), but your system does not have a suitable version of jsoncpp installed.

Please try cmake -DENABLE_SYSTEM_JSONCPP=0.

@ghost
Copy link

ghost commented Aug 18, 2016

@Rogier-5 I tried your suggestion but I'm still getting the No such file or directory error. I found a couple of entries in /build/android/jni/Android.mk that referenced /jni/src/json and modified those to /jni/src/jsoncpp/json but that didn't help either.

@Rogier-5
Copy link
Contributor Author

Rogier-5 commented Aug 18, 2016

modified those to /jni/src/jsoncpp/json but that didn't help either.

I think that for LOCAL_SRC_FILES, you need

LOCAL_SRC_FILES += jni/src/jsoncpp/json/jsoncpp.cpp

(which is how you probably changed it already)

and for LOCAL_C_INCLUDES, you need:

[...]
jni/src/jsoncpp                           \
[...]

which you probably changed to jni/src/jsoncpp/json instead ?

Does that help ?

@ghost
Copy link

ghost commented Aug 18, 2016

Changing the LOCAL_C_INCLUDES to jni/src/jsoncpp did the trick. Thanks.

@est31
Copy link
Contributor

est31 commented Aug 18, 2016

Mhhh these things need to be done on master as well...

@Rogier-5
Copy link
Contributor Author

@est31 naturally

@zing269 Are you planning to create a pull request ?

If not: I pushed a fix, but I haven't been able to compile-test it yet. Would you mind verifying that it works for you ? It is at https://github.com/Rogier-5/minetest/tree/json-android-fix.

@est31
Copy link
Contributor

est31 commented Aug 19, 2016

@Rogier-5 I confirm the android build works with your patch.

@ghost
Copy link

ghost commented Aug 19, 2016

@Rogier-5 Please go ahead and create the pull request. I'm still figuring out this whole git thing.

@Rogier-5
Copy link
Contributor Author

Rogier-5 commented Aug 19, 2016

In the mean time, I have managed to configure the android environment as well, and I can confirm too that compilation fails without the patch, and succeeds with patch.

@zing269: the following shell commands should work:

git clone https://github.com/minetest/minetest
cd minetest
git fetch https://github.com/Rogier-5/minetest json-android-fix:json-android-fix
git checkout json-android-fix
cd build/android
make

(if that's of any use)

@ghost
Copy link

ghost commented Aug 20, 2016

@Rogier-5 thanks, that is quite helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix 🐛 PRs that fix a bug @ Build CMake, build scripts, official builds, compiler and linker errors >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants