c++ - 获取/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
我不确定是什么导致了问题?
你能帮我解决上述错误吗?
解决方案
推荐阅读
- java - 在java中将.properties文件字符串转换为整数
- javascript - 如何使用特定字母对字符串数组进行排序?
- shell - 当 Maven 在 shell 脚本中构建失败时,在 Groovy 函数中返回布尔值
- web - 是否可能的产品被选中“订阅产品”字段自动创建订阅?
- c# - 如何在 C# 中传递变量的名称?
- php - 字符串到嵌套数组
- php - 允许访问 www/html 文件夹之外的文件
- python - max 和 np.max 的区别
- javascript - 遍历 json 对象,同时将其键值与 javascript 中的模式匹配
- c# - Dotvvm 运行时绑定到“对象”类型