BeastLounge icon indicating copy to clipboard operation
BeastLounge copied to clipboard

build error boost::json::to_value()

Open forresttales opened this issue 3 years ago • 11 comments

I downloaded from develop. I'm using boost_1_73_0. Also installed Boost.JSON and access it by including its directories. Also, I've copied json.hpp and json folder into boost. I assume I have everything I need.

However, in blackjack.cpp, "error: no member named 'to_value' in namespace 'boost::json'" I cannot even find a class or method 'to_value' in the folders or boost::json.

What am I missing?

forresttales avatar Jan 11 '21 00:01 forresttales

Which version of boost JSON did you download and from where?

madmongo1 avatar Jan 11 '21 07:01 madmongo1

I've tried the current version of... boostorg / json https://github.com/boostorg/json/tree/master

My json experience has been limited to boost::property_tree. So I assumed I needed more, although it's not explicit in the README, except JSON-RPC as an object description. And JSON-RPC is Python. Therefore, I used the above master branch.

The Boost Beast multi-chat example is very easy to run. It's a brilliant chat room example. But I'm looking for the proper way to set up 1 on 1 private instant messaging.

forresttales avatar Jan 11 '21 17:01 forresttales

By the looks of it the problem is that boost/json's public interface has changed a little, with respect to header files.

I think you'll need to also:

#include <boost/json/value_to.hpp>

madmongo1 avatar Jan 11 '21 18:01 madmongo1

Thanks for such a lightning fast reply. I tried value_to.hpp in blackjack.cpp. No dice. None of the current classes have to_value().

The line 267 in blackjack.cpp is... obj.emplace("hands", json::to_value(hands));

'hands' is declared just above it in the same 'struct seat'... std::vector<hand> hands;

Without inspecting things very deeply, I tried changing json::to_value to json::value_to and value_from. But these methods don't seem to like vectors.

The use of json information is used, also, in determining the chat room, itself. So, pulling it out could be messy. In channel_list.cpp, line 106, json::number_cast<std::size_t> 'number_cast' is also not recognized.

I can't find another boost json library in Google. So, I assume I'm in the right place. I've looked at both develop and master branches of boostorg /json.

Yeah, I guess BeastLounge doesn't accommodate all the changes made in Boost.JSON, as the latter seems more recent. I'll peel it like an onion, pulling out the BlackJack part and the json. 1 on 1 instant messaging is essentially a chatroom with only 2 clients, which is really what I want.

forresttales avatar Jan 11 '21 19:01 forresttales

Ah you’re right. It’s been changed to value_from()

madmongo1 avatar Jan 11 '21 20:01 madmongo1

There might be some more surgery necessary

madmongo1 avatar Jan 11 '21 20:01 madmongo1

In the BeastLounge master, in CMakeLists.txt, we have,

file (GLOB_RECURSE NLOHMANN_FILES ${PROJECT_SOURCE_DIR}/nlohmann/include/*.hpp )

This is a json library, https://github.com/nlohmann/json/tree/00cb98a3d170161711ab912ae6acefba31f29f75

But there is no nlohmann folder included in the project, nor explicitly mentioned.

So, for anyone interested in BeastLounge, I'd recommend the develop branch. Get Boost.JSON. Then, you'll have to perform that 'surgery', converting some of the json functions used in BeastLounge to match those in the current Boost.JSON.

I'll post any solutions I find in this thread.

forresttales avatar Jan 11 '21 22:01 forresttales

This project is not really fit for public consumption yet.

vinniefalco avatar Jan 12 '21 23:01 vinniefalco

Appreciate it. I've been using your advanced Beast server for maybe 4 years for our company's database programs. It's been awesome!

I'm sure you've seen this run when you built it. And I'm stubborn ))

Actually, BeastLounge DOES COMPILE if you use an older Boost.JSON, develop

https://github.com/ayounes-synaptics/json/blob/develop/CMakeLists.txt

And in ayounes-synaptics CMakeLists.txt, comment out,

add_subdirectory(bench) -> especially add_subdirectory(example) add_subdirectory(test)

$ cmake . $ make Add the resulting libboost_json.a to the linker path. Add the json folder, json.hpp, pilfer.hpp to boost. Compiles well.

Program runs, page comes up. But when connecting... I'm stuck at a runtime error in ws_user.cpp in ws_session_base::do_write,

    impl()->ws().async_write(
        mq_.back(),
        beast::bind_front_handler(
            &ws_session_base::on_write,
            boost::shared_from(this),
            mq_.size() - 1));

Right here when async_write is called, I get 'Segmentation fault (core dumped)'. Execution does not enter on_write().

A little cout inspection gives, mq_.size() = 1 boost::shared_from(this) = 0x80208d160

But I get a value of 1 for the reference, &ws_session_base::on_write = 1

I've been using either C++11 or 17, CLang on FreeBSD. Any reason why asyc_write would fail?

forresttales avatar Jan 13 '21 02:01 forresttales

Segfault when calling an initiating function implies that the previous handler didn’t capture lifetimes properly. Segfault in the completion handler implies you didn’t capture lifetimes correctly in the handler.

madmongo1 avatar Jan 13 '21 07:01 madmongo1

Thx. I didn't solve it. But apparently, someone else has.

https://github.com/5l1v3r1/BeastLounge

This fork with the json to which it links, builds and runs fine. The game plays with no errors.

For Code::Blocks users, My links look like, -lssl -lcrypto -lpthread -lboost_thread

You'll need crypto. I needed both threads.

Add, libboost_json, explicitly to Link libraries (once you've build it, libboost_json.a).

config.json may be finicky. Mine looks like,

{
    "listeners": [
        {
            "name" : "ipv4",
            "address" : "127.0.0.1",
            "port_num" : 3003
        }
    ],

    "server": {
      "threads" : 5,
      "doc-root" : "wwwroot"
    },

    "log" : {
      "path" : "log.txt"
    }
}

I used boost 1_73_0.

forresttales avatar Jan 18 '21 08:01 forresttales