baidu / unit-dmkit

https://ai.baidu.com/unit/v2#/dmKit
Apache License 2.0
327 stars 116 forks source link

wsl下ubuntu18编译brpc时出错 #81

Open a0soft opened 5 years ago

a0soft commented 5 years ago

Installing dependencies for Ubuntu... [sudo] password for uuu: Reading package lists... Done Building dependency tree Reading state information... Done coreutils is already the newest version (8.28-1ubuntu1). libgoogle-perftools-dev is already the newest version (2.5-2.2ubuntu3). libleveldb-dev is already the newest version (1.20-2). libprotobuf-dev is already the newest version (3.0.0-9.1ubuntu1). libprotoc-dev is already the newest version (3.0.0-9.1ubuntu1). libsnappy-dev is already the newest version (1.1.7-1). make is already the newest version (4.1-9.1ubuntu1). libgflags-dev is already the newest version (2.2.1-1). protobuf-compiler is already the newest version (3.0.0-9.1ubuntu1). g++ is already the newest version (4:7.4.0-1ubuntu2.3). git is already the newest version (1:2.17.1-1ubuntu0.4). libcurl4-openssl-dev is already the newest version (7.58.0-2ubuntu3.7). libssl-dev is already the newest version (1.1.1-1ubuntu2.1~18.04.4). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Building brpc... -- The C compiler identification is GNU 7.4.0 -- The CXX compiler identification is GNU 7.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found gflags: /usr/lib/x86_64-linux-gnu/libgflags.so -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread (found version "3.9.0") -- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1") -- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.so;-lpthread;-lpthread (found version "3.9.0") -- Configuring done -- Generating done -- Build files have been written to: /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/_build

[ 71%] Building CXX object src/CMakeFiles/OBJ_LIB.dir/brpc/esp_message.cpp.o [ 71%] Building CXX object CMakeFiles/PROTO_LIB.dir/brpc/streaming_rpc_meta.pb.cc.o In file included from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:18:0: /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.h:37:47: error: invalid use of incomplete type ‘class google::protobuf::Message’ class EspMessage : public ::google::protobuf::Message { ^~~ In file included from /usr/include/google/protobuf/implicit_weak_message.h:37:0, from /usr/include/google/protobuf/generated_message_util.h:49, from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.h:21, from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:18: /usr/include/google/protobuf/arena.h:76:7: note: forward declaration of ‘class google::protobuf::Message’ class Message; // defined in message.h ^~~ In file included from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:24:0: /usr/include/google/protobuf/wire_format_lite_inl.h:61:13: error: redefinition of ‘static bool google::protobuf::internal::WireFormatLite::ReadPrimitive(google::protobuf::io::CodedInputStream, CType) [with CType = int; google::protobuf::internal::WireFormatLite::FieldType DeclaredType = (google::protobuf::internal::WireFormatLite::FieldType)5]’ inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_INT32>( ^~~~~~ In file included from /usr/include/google/protobuf/generated_message_util.h:53:0, from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.h:21, from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:18: /usr/include/google/protobuf/wire_format_lite.h:918:13: note: ‘static bool google::protobuf::internal::WireFormatLite::ReadPrimitive(google::protobuf::io::CodedInputStream, CType) [with CType = int; google::protobuf::internal::WireFormatLite::FieldType DeclaredType = (google::protobuf::internal::WireFormatLite::FieldType)5]’ previously declared here inline bool WireFormatLite::ReadPrimitive<int32, WireFormatLite::TYPE_INT32>( ^~~~~~ In file included from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:24:0: /usr/include/google/protobuf/wire_format_lite_inl.h:70:13: error: redefinition of ‘static bool google::protobuf::internal::WireFormatLite::ReadPrimitive(google::protobuf::io::CodedInputStream, CType) [with CType = long int; google::protobuf::internal::WireFormatLite::FieldType DeclaredType = (google::protobuf::internal::WireFormatLite::FieldType)3]’ inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_INT64>( ^~~~~~ In file included from /usr/include/google/protobuf/generated_message_util.h:53:0, from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.h:21, from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:18: /usr/include/google/protobuf/wire_format_lite.h:926:13: note: ‘static bool google::protobuf::internal::WireFormatLite::ReadPrimitive(google::protobuf::io::CodedInputStream, CType) [with CType = long int; google::protobuf::internal::WireFormatLite::FieldType DeclaredType = (google::protobuf::internal::WireFormatLite::FieldType)3]’ previously declared here inline bool WireFormatLite::ReadPrimitive<int64, WireFormatLite::TYPE_INT64>( ^~~~~~ [ 71%] Building CXX object src/CMakeFiles/OBJ_LIB.dir/brpc/event_dispatcher.cpp.o In file included from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:24:0: /usr/include/google/protobuf/wire_format_lite_inl.h:79:13: error: redefinition of ‘static bool google::protobuf::internal::WireFormatLite::ReadPrimitive(google::protobuf::io::CodedInputStream, CType) [with CType = unsigned int; google::protobuf::internal::WireFormatLite::FieldType DeclaredType = (google::protobuf::internal::WireFormatLite::FieldType)13]’ inline bool WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_UINT32>( ^~~~~~ In file included from /usr/include/google/protobuf/generated_message_util.h:53:0, from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.h:21, from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:18: /usr/include/google/protobuf/wire_format_lite.h:934:13: note: ‘static bool google::protobuf::internal::WireFormatLite::ReadPrimitive(google::protobuf::io::CodedInputStream, CType) [with CType = unsigned int; google::protobuf::internal::WireFormatLite::FieldType DeclaredType = (google::protobuf::internal::WireFormatLite::FieldType)13]’ previously declared here inline bool WireFormatLite::ReadPrimitive<uint32, WireFormatLite::TYPE_UINT32>( ^~~~~~ In file included from /home/catching/work/dev/baidu/dmkit/unit-dmkit/brpc/src/brpc/esp_message.cpp:24:0: /usr/include/google/protobuf/wire_format_lite_inl.h:85:13: error: redefinition of ‘static bool google::protobuf::internal::WireFormatLite::ReadPrimitive(google::protobuf::io::CodedInputStream, CType) [with CType = long unsigned int; google::protobuf::internal::WireFormatLite::FieldType DeclaredType = (google::protobuf::internal::WireFormatLite::FieldType)4]’ inline bool WireFormatLite::ReadPrimitive<uint64, WireFormatLite::TYPE_UINT64>( ^~~~~~

a0soft commented 5 years ago

折腾了好些时间,下面列出较完整的编译过程,以便能帮到遇到类似情形的开发者

00、安装Ubuntu下C/C++开发工具

01、下载dmkit

进入dmkit目录

cd ./PATH_TO_DMKIT

克隆dmkit

git clone https://github.com/baidu/unit-dmkit.git

02、下载编译protobuf3.6.0,正确的版本很重要!!!否则可能出现链接错误

安装protobuf需要的库和工具

sudo apt-get install autoconf automake libtool curl make g++ unzip

克隆版本为3.6.0的protobuf源码

git clone -b v3.6.0 https://github.com/protocolbuffers/protobuf.git

进入protobuf目录

cd protobuf

克隆protobuf的子模块,主要是gtest

git submodule update --init --recursive

确保处于protobuf目录

cd protobuf

主要工作

./autogen.sh ./configure --prefix=/usr -with-PACKAGE=yes sudo make

若没有克隆子模块,则

make check会失败,

但可以make install,

使用某些功能时可能会出错.

make check sudo make install

refresh shared library cache

sudo ldconfig

若输出protobuf版本信息(libprotoc 3.6.0)则表示安装成功

protoc --version

03、下载编译brpc,正确的版本很重要!!!否则可能出现链接错误 参考"https://blog.csdn.net/breaksoftware/article/details/81564405" 修改deps.sh成这样子 cd brpc git checkout master

git pull
git checkout 2ae7f04ce513c6aee27545df49d5439a98ae3a3f

04、安装依赖的剩余部分

sh deps.sh ubuntu

sh deps.sh none

mkdir _build && cd _build && cmake ..

修改CMakeCache.txt

BRPC_INCLUDE_PATH:PATH=/home/USER/PATH_TO_DMKIT/unit-dmkit/brpc/_build/output/include

必要时make clean

make

a0soft commented 5 years ago

这里提供一个基于bot_emulator.py修改后的文件bot_emulator4.py, 其需要4个参数 [bot_id] 机器人ID [client_id] 通过官网获取的AK [client_secret] 通过官网获取的SK [ip_and_port] DMKit服务提供者的IP和端口 调用示例 python bot_emulator4.py 73999 XXXXclient_idXXXX XXXXclient_secretXXXX http://a0ls-00000003:8010

-- coding: utf-8 --

Copyright (c) 2018 Baidu, Inc. All Rights Reserved.

#

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

#

http://www.apache.org/licenses/LICENSE-2.0

#

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

#

""" A simple console program to emulate a bot for user to interact with

""" import json import os import random import requests import sys import urllib, urllib.request import ssl

调用形式 python bot_emulator4.py [bot_id] [client_id] [client_secret] [ip_and_port]

调用示例 python bot_emulator4.py 73999 XXXXclient_idXXXX XXXXclient_secretXXXX http://a0ls-00000003:8010

输入exitexit时退出

def main(bot_id, client_id, client_secret, ip_and_port): """ Bot emulator Read user input and get bot response

"""
# 2019-08-12, added for get access_token by a0soft@163.com, BEG
# client_id 为官网获取的AK,client_secret 为官网获取的SK
host = ''.join(
    ['https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=',
    client_id,
    '&client_secret=',
    client_secret])
print(host)
request = urllib.request.Request(host)
request.add_header('Content-Type', 'application/json; charset=UTF-8')
response = urllib.request.urlopen(request)
content = response.read()
if (content):
    resp_json = json.loads(content)
    token = resp_json["access_token"]
    print(token)
# 2019-08-12, added for get access_token by a0soft@163.com, END
# Url of dmkit, change this if you are runnning dmkit in a different ip/port.
url = ''.join([ip_and_port, "/search?access_token=", token])

json_header = {'Content-Type': 'application/json'}
user_id = str(random.randint(1, 100000))
session = ""
while True:
    print ("-----------------------------------------------------------------")
    user_input = input("input:\n")
    user_input = user_input.strip()
    # 退出接口
    if (user_input == "exitexit"):
        break
    if not user_input:
        continue
    logid = str(random.randint(100000,999999))
    payload = {
        "version": "2.0",
        "bot_id": bot_id,
        "log_id": logid,
        "request": {
            "user_id": user_id,
            "query": user_input,
            "query_info": {
                "type": "TEXT",
                "source": "ASR",
                "asr_candidates": []
            },
            "updates": "",
            "client_session": "{\"client_results\":\"\", \"candidate_options\":[]}",
            "bernard_level": 1
        },
        "bot_session": session
    }
    obj = requests.post(url, data=json.dumps(payload), headers=json_header).json()
    print ("BOT:")
    # Not a valid response.
    if obj['error_code'] != 0:
        print ("ERROR: %s" % obj['error_msg'])
        continue

    session = obj['result']['bot_session']
    response = obj['result']['response']
    action = response['action_list'][0]
    # For clarify or failed responses which dmkit does not take actions.
    if action['type'] != 'event':
        print (action['say'])
        continue

    custom_reply = json.loads(action['custom_reply'])
    if custom_reply['event_name'] != 'DM_RESULT':
        print ('ERROR:unknown event name %s' % custom_reply['event_name'])
        continue
    # This is a dmkit response
    dm_result = json.loads(custom_reply['result'])
    for item in dm_result['result']:
        if item['type'] == 'tts':
            print (item['value'])

if name == "main":

if len(sys.argv) < 2:

#    print ("Usage: %s %s %s" % (sys.argv[0], "[bot_id]", "[access_token]"))
#else:
#    main(sys.argv[1], sys.argv[2])
if len(sys.argv) < 4:
    print ("Usage: %s %s %s %s %s" % (sys.argv[0], "[bot_id]", "[client_id]", "[client_secret]", "[ip_and_port]"))
else:
    main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])