lightning community daemon – Hyperlink fails when constructing gRPC consumer for LND in C++

on

|

views

and

comments


I am making an attempt to construct a gRPC consumer for LND in C++, beginning with the WalletBalance perform. I’ve by no means used gRPC earlier than, and I take advantage of make as a substitute of cmake, however in keeping with the documentation that is imagined to be doable. I’m utilizing the pkg-config information that get put in with gRPC, however they aren’t working.

Here’s what I’ve efficiently been ready to take action far.

  1. Construct gRPC
  2. Compile lightning.proto
  3. Compile lightning.pb.cc and lightning.grpc.pb.cc
  4. Hyperlink with lightning.pb.cc.o (however not lightning.grpc.pb.cc.o)

That is my cpp file:

#embrace <iostream>
#embrace <string>

#embrace <grpcpp/grpcpp.h>

#embrace "lightning.grpc.pb.h"
#embrace "lightning.pb.h"

utilizing namespace std;
utilizing namespace lnrpc;

utilizing grpc::Channel;
utilizing grpc::ClientContext;
utilizing grpc::Standing;

class LightningClient
{
personal:
    unique_ptr<Lightning::Stub> stub_;

public:
    LightningClient (shared_ptr<grpc::Channel> channel) : stub_ (Lightning::NewStub (channel)) {}

    unsigned lengthy WalletBalance (const string& person)
    {
        WalletBalanceRequest request;
        WalletBalanceResponse reply;
        ClientContext context;

        Standing standing = stub_->WalletBalance (&context, request, &reply);

        if (standing.okay ())
            return reply.total_balance ();
        else
            cout << standing.error_code () << ": " << standing.error_message () << endl;

        return 0;
    }
};

int foremost (int argc, char *argv [])
{
    shared_ptr<grpc::Channel> channel;// = CreateChannel ("localhost:10009", grpc::InsecureChannelCredentials ());
    return 0;
}

That is my makefile:

lnd-grpc-client : lnd-grpc-client.o lightning.pb.cc.o lightning.grpc.pb.cc.o
    g++-10 -pthread -o lnd-grpc-client lnd-grpc-client.o lightning.pb.cc.o `pkg-config --libs --static protobuf`

lightning.grpc.pb.cc.o : lightning.grpc.pb.cc
    g++-10 -std=c++20 `pkg-config protobuf --cflags` -c -o lightning.grpc.pb.cc.o lightning.grpc.pb.cc

lightning.pb.cc.o : lightning.pb.cc
    g++-10 -std=c++20 `pkg-config protobuf --cflags` -c -o lightning.pb.cc.o lightning.pb.cc

lnd-grpc-client.o : lnd-grpc-client.cpp
    g++-10 -std=c++20 `pkg-config protobuf --cflags` -c -o lnd-grpc-client.o lnd-grpc-client.cpp

All of that compiles and hyperlinks simply advantageous. However I’ve the CreateChannel perform commented out in my cpp file and I’m not linking with lightning.grpc.pb.cc.o, each of which might be required if I’m to get this working.

If I uncomment the CreateChannel perform, it provides me a linker error saying undefined reference to 'grpc::InsecureChannelCredentials()'. However there doesn’t appear to be any pkg-config that solves that drawback.

If I attempt to hyperlink with lightning.grpc.pb.cc.o, I get a whole lot of linker errors. I can not publish all of them, however listed here are a number of:

lightning.grpc.pb.cc:(.textual content._ZN4grpc5SliceD2Ev[_ZN4grpc5SliceD5Ev]+0x20): undefined reference to 'grpc_slice_unref'
/usr/bin/ld: lightning.grpc.pb.cc.o: in perform 'grpc::Slice::Slice(unsigned lengthy)':
lightning.grpc.pb.cc:(.textual content._ZN4grpc5SliceC2Em[_ZN4grpc5SliceC5Em]+0x32): undefined reference to 'grpc_slice_malloc'
/usr/bin/ld: lightning.grpc.pb.cc.o: in perform 'grpc::SliceReferencingString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
lightning.grpc.pb.cc:(.textual content._ZN4grpc22SliceReferencingStringERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN4grpc22SliceReferencingStringERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x50): undefined reference to 'grpc_slice_from_static_buffer'
/usr/bin/ld: lightning.grpc.pb.cc.o: in perform 'grpc::ByteBuffer::ByteBuffer(grpc::Slice const*, unsigned lengthy)':
lightning.grpc.pb.cc:(.textual content._ZN4grpc10ByteBufferC2EPKNS_5SliceEm[_ZN4grpc10ByteBufferC5EPKNS_5SliceEm]+0x27): undefined reference to 'grpc_raw_byte_buffer_create'
/usr/bin/ld: lightning.grpc.pb.cc.o: in perform 'grpc::ByteBuffer::~ByteBuffer()':
lightning.grpc.pb.cc:(.textual content._ZN4grpc10ByteBufferD2Ev[_ZN4grpc10ByteBufferD5Ev]+0x27): undefined reference to 'grpc_byte_buffer_destroy'
/usr/bin/ld: lightning.grpc.pb.cc.o: in perform 'grpc::ByteBuffer::Clear()':
lightning.grpc.pb.cc:(.textual content._ZN4grpc10ByteBuffer5ClearEv[_ZN4grpc10ByteBuffer5ClearEv]+0x27): undefined reference to 'grpc_byte_buffer_destroy'

I attempted including the grpc and grpc++ pkg-config information to my makefile’s hyperlink command, however that didn’t remedy the issue.

Has anybody really constructed a gRPC consumer for LND in C++? In that case, how have you learnt which libraries to hyperlink with and the way do you hyperlink with them?

Share this
Tags

Must-read

Constructing the Torc Driverless Security Case

At Torc, we’ve structured our security case on three foundational pillars: Engineer It to Be Secure, Function It to Be Secure, and the...

What’s DL+S? Unlocking the Huge Information Required to Develop Autonomous Vans

Breakthroughs in AI for autonomous driving don't occur in isolation. They occur when information, simulation, machine studying, infrastructure, and car testing work as...

Why I can’t wait to get right into a driverless automotive | Self-driving automobiles

Adrian Chiles (Driverless automobiles are taking us on a street to nowhere, 10 September) needs to know who requested for driverless automobiles. I...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here