c++ - mapreduce c 编程无法与 -fPIC 链接,如何解决?

标签 c++ hadoop mapreduce linker fpic

我有一个示例程序如下,ubunt 18.04 上的 w.cpp,g++7.3.0

#include<algorithm>
#include<limits>
#include<string>
#include"stdint.h"
#include"Pipes.hh"
#include"TemplateFactory.hh"
#include"StringUtils.hh"
using namespace std;
using namespace HadoopPipes;
using namespace HadoopUtils;
class wMapper:public Mapper{
public:
    wMapper(TaskContext&){}
    void map(MapContext& context){
        string line = context.getInputValue();
        vector<string> words = splitString(line, " ");
        for(size_t i=0;i<words.size();++i){
            context.emit(words[i], toString(i));
        }
    }
};
class wReducer:public Reducer{
public:
    wReducer(TaskContext&){}
    void reduce(ReduceContext& context){
        int count = 0;
        while(context.nextValue()){
            count += toInt(context.getInputValue());
        }
        context.emit(context.getInputKey(), toString(count));
    }
};
int main(){
    return HadoopPipes::runTask(TemplateFactory<wMapper, wReducer>());
}

然后我编译它:

g++ w.cpp -I$HADOOP_LIB/include -I$HADOOP_HOME/include \ 
-I$JAVA_HOME/include -L$HADOOP_LIB/native -lhadooppipes -lhadooputils 
-lpthread -lcrypto -o w -fPIC

报错:

/usr/bin/x86_64-linux-gnu-ld: /opt/hadoop-2.8.4/lib/native/libhadooppipes.a(HadoopPipes.cc.o): relocation R_X86_64_32S against symbol `_ZNSs4_Rep20_S_empty_rep_storageE@@GLIBCXX_3.4' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /opt/hadoop-2.8.4/lib/native/libhadooputils.a(StringUtils.cc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: /opt/hadoop-2.8.4/lib/native/libhadooputils.a(SerialUtils.cc.o): relocation R_X86_64_32S against symbol `_ZTVN11HadoopUtils12FileInStreamE' can not be used when making a PIE object; recompile with -fPIC

无论我添加或删除“-fPIC”标志,同样的错误。

最佳答案

问题是:

  1. 您的编译器配置为构建position-independent executables默认情况下,
  2. 您正在链接的一些库(特别是 libhadooppipes.a)以允许它们链接到 PIE 二进制文件的方式编译。

解决方案:将-nopie 添加到您的链接命令行。

关于c++ - mapreduce c 编程无法与 -fPIC 链接,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52126073/

相关文章:

c++ - 在 C++20 中实现没有预处理器的断言

python - 使用 Hive 的 TRANSFORM 命令在 Hadoop 表中写入 python 脚本的输出

hadoop - 如何将初始化数据插入配置单元中的表?

python - 检查用python编写的配置单元udf中的错误

python - 如何进行 3 阶段 Map Reduce 流式处理?

java - 给定一个数字数组,使用 Map Reduce 返回所有其他数字的乘积数组

c++ - boost 日志 : File Rotation

C++ 用其他类型的值替换成员变量

c++ - 内存布局练习 C++

hadoop - 如何详细获取hdfs使用报告