美文网首页
use google quiche as library

use google quiche as library

作者: help_youself | 来源:发表于2020-08-12 17:05 被阅读0次

    Reason

    The reason is simple: There are always so many projects that are not managered by build.gn.
    1 install llvm
    Reference:
    2 download chromium project
    I choose naiveproxy.
    3 change some compiling flags in build.sh

      out=out/Release
      flags="
        clang_base_path=\"/usr\"
        clang_use_chrome_plugins=false
        use_custom_libcxx=false
        is_official_build=false
        exclude_unwind_tables=true
        enable_resource_whitelist_generation=false
        is_component_build=true
        target_cpu=\"x64\"
        symbol_level=0"
    

     After several error, I found the net library is denpended on libstdc++ instead of libc++.

    Sample

    test.cc

    #include "base/logging.h"
    #include "base/sys_byteorder.h"
    #include "net/third_party/quiche/src/quic/core/quic_versions.h"
    #include "net/third_party/quiche/src/quic/core/quic_framer.h"
    #include "net/third_party/quiche/src/quic/core/quic_data_writer.h"
    #include "net/third_party/quiche/src/quic/core/quic_stream_send_buffer.h"
    #include "net/third_party/quiche/src/quic/core/quic_simple_buffer_allocator.h"
    #include "net/base/ip_address.h"
    #include "base/strings/strcat.h"
    #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
    #include "base/strings/strcat.h"
    //#include "gtest/gtest.h"
    #include <string>
    #include <iostream>
    using namespace quic;
    using namespace net;
    using namespace std;
    bool MockLogMessageHandler(int severity,
        const char* file, int line, size_t message_start, const std::string& str) {
        std::cout<<file<<" "<<line<<" "<<str<<std::endl;
      return false;
    }
    using namespace logging;
    int main(){
    
        uint32_t bps=1000000;
        QuicBandwidth bw=QuicBandwidth::FromBitsPerSecond(bps);
        std::cout<<"hello world "<<bw<<std::endl;
    
        base::StringPiece ip4("127.0.0.2");
        base::StringPiece ip6("2001:db8:1020:3040:5060:7080:90a0:b0c0");
        std::cout<<std::string(ip4.data())<<std::endl;
        IPAddress ip1;
        std::cout<<"shit "<<ip1.ToString()<<std::endl;
        ip1.AssignFromIPLiteral(ip4);
        std::cout<<ip1.ToString()<<std::endl;
        return 0;
    }
    

    CMakeLists.txt

    PROJECT(project)
    cmake_minimum_required(VERSION 2.6)
    set(CMAKE_CXX_STANDARD 14)
    
    set(CMAKE_CXX_COMPILER "clang++")
    set(CMAKE_C_COMPILER "clang")
    
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
    
    
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    SET(CMAKE_BUILD_TYPE "Release")
    #add_definitions(-DNDEBUG)
    add_definitions(${CMAKE_C_FLAGS})
    
    set(LIB_INC  ${PROJECT_SOURCE_DIR}/../naiveproxy/src)
    set(LIB_DIR  ${PROJECT_SOURCE_DIR}/../naiveproxy/src/out/Release/obj)
    
    include_directories(${LIB_INC})
    LINK_DIRECTORIES(${PROJECT_SOURCE_DIR}/../naiveproxy/src/out/Release) ## for so
    
    
    set(THIRD_LIB  ${PROJECT_SOURCE_DIR}/../naiveproxy/src/out/Release/obj/third_party)
    
    
    set(GEN_DIR  ${PROJECT_SOURCE_DIR}/../naiveproxy/src/out/Release/gen)
    include_directories(${GEN_DIR}/)  #gen/base/logging_buildflags.h  gen/net/net_buildflags.h
    set(EXECUTABLE_NAME "my_test")
    add_executable(${EXECUTABLE_NAME} test.cc)
    target_link_libraries(${EXECUTABLE_NAME} net base protobuf_lite)#net base protobuf_lite boringssl pthread chrome_zlib
    
    # cmake .. -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++   -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libstdc++
    #export LD_LIBRARY_PATH=/home/zsy/chromium/naiveproxy/src/out/Release
    
    
    ## ldd  libnet.so
    ## libstdc++.so.6 
    

    Build

    mkdir build && cd build 
    cmake .. -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++   -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libstdc++
    make
    

    [1] llvm-install
    [2] naiveproxy

    相关文章

      网友评论

          本文标题:use google quiche as library

          本文链接:https://www.haomeiwen.com/subject/zsrmdktx.html