首页 > 解决方案 > 获取/libgcc_s.so.1:版本'GCC_3.4'不存在:使用librdkafka库测试c ++程序时出错

问题描述

我正在使用 Solaris OS 中的 librdkafka 库编译以下示例 C++ kafka 生产者程序,并在链接时出错:

示例程序:

#include <iostream>
#include "rdkafkacpp.h"


int static producer_1()
{
    std::string brokers = "127.0.0.1";
    std::string errstr;
    std::string topic_str = "linli";
    std::string mode;
    std::string debug;
    int32_t partition = RdKafka::Topic::PARTITION_UA;
    int64_t start_offset = RdKafka::Topic::OFFSET_BEGINNING;
    bool do_conf_dump = false;
    int opt;
    // MyHashPartitionerCb hash_partitioner;
    int use_ccb = 0;

    /*
    * Create configuration objects
    */
    RdKafka::Conf *conf = RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL);
    RdKafka::Conf *tconf = RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC);

    conf->set("metadata.broker.list", brokers, errstr);

    RdKafka::Producer *producer = RdKafka::Producer::create(conf, errstr);
    if (!producer) {
        std::cerr << "Failed to create producer: " << errstr << std::endl;
        exit(1);
    }

    std::cout << "% Created producer " << producer->name() << std::endl;

    /*
    * Create topic handle.
    */
    RdKafka::Topic *topic = NULL;
    if (!topic_str.empty()) {
        topic = RdKafka::Topic::create(producer, topic_str, tconf, errstr);
        if (!topic) {
            std::cerr << "Failed to create topic: " << errstr << std::endl;
            exit(1);
        }
    }

    RdKafka::ErrorCode resp = producer->produce(topic, partition,
        RdKafka::Producer::RK_MSG_COPY /* Copy payload */,
        const_cast<char *>("hello worlf"), 11,
        NULL, NULL);

    delete topic;
    delete producer;
    return 0;
}


int static producer_2()
{
    std::string brokers = "127.0.0.1";
    std::string errstr;
    std::string topic_str = "linli";
    std::string mode;
    std::string debug;
    int32_t partition = RdKafka::Topic::PARTITION_UA;
    int64_t start_offset = RdKafka::Topic::OFFSET_BEGINNING;
    bool do_conf_dump = false;
    int opt;
    // MyHashPartitionerCb hash_partitioner;
    int use_ccb = 0;

    RdKafka::Conf *conf = RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL);
    RdKafka::Conf *tconf = RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC);

    conf->set("metadata.broker.list", brokers, errstr);

    RdKafka::Producer *producer = RdKafka::Producer::create(conf, errstr);
    if (!producer) {
        std::cerr << "Failed to create producer: " << errstr << std::endl;
        exit(1);
    }

    std::cout << "% Created producer " << producer->name() << std::endl;

    RdKafka::ErrorCode resp = producer->produce(topic_str, partition,
        RdKafka::Producer::RK_MSG_COPY /* Copy payload */,
        (void *)"hi", 2,
        NULL, 0, 0, NULL);



    std::string errs(RdKafka::err2str(resp));
    std::cout << errs << std::endl;
    //producer->poll(0);


    delete producer;

    return 0;
}


int main()
{

    producer_2();

    return 0;
}

重现问题的步骤:

已安装 Apache kafka:kafka_2.13-3.0.0 用于 kafka 的 C++ API 库:librdkafka++.so.1

使用CC编译如下图:

CC KafkaProducerConsumer.cc librdkafka++.so.1

代码正在编译成功,但在链接时返回以下错误:

"rdkafkacpp.h", line 2139: Warning: Identifier expected instead of "}".
1 Warning(s) detected.
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_3.3' does not exist:
        required by file /opt/csw/lib/sparcv8/libstdc++.so.6
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_3.4' does not exist:
        required by file /opt/csw/lib/sparcv8/libstdc++.so.6
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_4.2.0' does not exist:
        required by file /opt/csw/lib/sparcv8/libstdc++.so.6
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_3.4' does not exist:
        required by file /opt/csw/lib/sparcv8/librdkafka.so.1
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_4.3.0' does not exist:
        required by file /opt/csw/lib/sparcv8/librdkafka.so.1
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_3.4' does not exist:
        required by file /opt/csw/lib/sparcv8/liblz4.so.1
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_4.3.0' does not exist:
        required by file /opt/csw/lib/sparcv8/liblz4.so.1
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_3.4' does not exist:
        required by file /opt/csw/lib/sparcv8/libzstd.so.1
ld: fatal: file /p2k/L10.93A/bld/bin/libgcc_s.so.1: version 'GCC_4.3.0' does not exist:
        required by file /opt/csw/lib/sparcv8/libzstd.so.1
ld: fatal: file processing errors. No output written to a.out

我不确定是什么导致了问题?

你能帮我解决上述错误吗?

标签: c++githubapache-kafkaproducerlibrdkafka

解决方案


推荐阅读