g++编译.pb.cc文件的命令

protobuf的测试文件,test.proto: 

syntax = "proto3";
package mytest;

message LoginRequest
{
    string name=1;
    string pwd=2;
}

message LoginResponse
{
    int32 errcode=1;
    string errmsg=2;
    bool success=3;
}

使用protoc编译,protoc test.proto --cpp_out=./

生成test.pb.h和test.pb.cc。

测试代码

main.cc

#include "test.pb.h"
#include <iostream>
#include <string>

using namespace mytest;

int main()
{
    LoginRequest req;
    req.set_name("xiaoxie");
    req.set_pwd("123456");

    std::string send_str;
    if (req.SerializeToString(&send_str))
    {
        std::cout << send_str.c_str() << std::endl;
    }

    return 0;
}

 使用g++进行编译,库的顺序非常重要。

g++ -o main288 main.cc test.pb.cc -lprotobuf \
-labsl_log_internal_check_op \
-labsl_log_internal_conditions \
-labsl_log_internal_message \
-labsl_log_internal_nullguard \
-labsl_examine_stack \
-labsl_log_internal_format \
-labsl_log_internal_proto \
-labsl_log_internal_log_sink_set \
-labsl_log_sink \
-labsl_log_initialize \
-labsl_log_internal_globals \
-labsl_log_globals \
-labsl_raw_hash_set \
-labsl_hash \
-labsl_city \
-labsl_low_level_hash \
-labsl_statusor \
-labsl_status \
-labsl_cord \
-labsl_cordz_info \
-labsl_cord_internal \
-labsl_cordz_functions \
-labsl_exponential_biased \
-labsl_cordz_handle \
-labsl_crc_cord_state \
-labsl_crc32c \
-labsl_crc_internal \
-labsl_strerror \
-labsl_str_format_internal \
-labsl_synchronization \
-labsl_stacktrace \
-labsl_symbolize \
-labsl_debugging_internal \
-labsl_demangle_internal \
-labsl_graphcycles_internal \
-labsl_kernel_timeout_internal \
-labsl_malloc_internal \
-labsl_time \
-labsl_time_zone \
-lutf8_validity \
-labsl_strings \
-labsl_int128 \
-labsl_strings_internal \
-labsl_base \
-labsl_spinlock_wait \
-labsl_throw_delegate \
-labsl_raw_logging_internal \
-labsl_log_severity

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值