代码之家  ›  专栏  ›  技术社区  ›  Troskyvs

mapreduce c程序与-fPIC链接失败,如何修复?

  •  0
  • Troskyvs  · 技术社区  · 6 年前

    #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 回复  |  直到 6 年前
        1
  •  1
  •   Employed Russian    6 年前

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

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