c ++主要可执行错误的隐式入口/启动

时间:2018-04-20 03:34:24

标签: c++ makefile

我在Mac上运行Hadoop管道代码时遇到问题。 这是我的c ++代码。

#include <algorithm>
#include <limits>
#include <stdint.h>
#include <string>

#include "Pipes.hh"
#include "TemplateFactory.hh"
#include "StringUtils.hh"
using namespace std;

class MaxTemperatureMapper : public HadoopPipes::Mapper {
public:
  MaxTemperatureMapper(HadoopPipes::TaskContext& context) {
  }
  void map(HadoopPipes::MapContext& context) {
    std::string line = context.getInputValue();
    std::string year = line.substr(15, 4);
    std::string airTemperature = line.substr(87, 5);
    std::string q = line.substr(92, 1);
    if (airTemperature != "+9999" &&
        (q == "0" || q == "1" || q == "4" || q == "5" || q == "9")) {
      context.emit(year, airTemperature);
    }
  }
};

class MapTemperatureReducer : public HadoopPipes::Reducer {
public:
  MapTemperatureReducer(HadoopPipes::TaskContext& context) {
  }
  void reduce(HadoopPipes::ReduceContext& context) {
    int maxValue = INT_MIN;
    while (context.nextValue()) {
      maxValue = std::max(maxValue, HadoopUtils::toInt(context.getInputValue()));
    }
    context.emit(context.getInputKey(), HadoopUtils::toString(maxValue));
  }
};

int main(int argc, char * argv[]) {

    int i=HadoopPipes::runTask(HadoopPipes::TemplateFactory<WordCountMap, WordCountReduce>()); // 运行任务
    return 0;
}

我的makefile是:

wordcount :wordcount.cpp
    g++ -Wall -I/Users/macbookpro/Documents/hadoop-2.7.5/include -L/Users/macbookpro/Documents/hadoop-2.7.5/lib/native -lhadooppipes -lhadooputils -lpthread -lcrypto -lssl -g -O2 -o $@

当我尝试编译源文件时,我收到错误消息

  

架构x86_64的未定义符号:&#34; _main&#34;,引自:        主要可执行文件的隐式输入/启动ld:找不到架构x86_64 clang的符号:错误:链接器命令失败并退出   代码1(使用-v查看调用)make:*** [wordcount]错误1

我不知道这意味着什么,因为我已经有了一个主要功能。

你可以解决这个问题吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

您没有将源文件传递给配方,这里最简单的避免方法就是依靠内置的make-rule来实现一次性程序,您只需要:

CPPFLAGS := -I/Users/macbookpro/Documents/hadoop-2.7.5/include -pthread
CXXFLAGS := -Wall -g -O2
LDFLAGS  := -L/Users/macbookpro/Documents/hadoop-2.7.5/lib/native -pthread 
LDLIBS   := -lhadooppipes -lhadooputils -lcrypto -lssl

wordcount:

%: %.cpp的make隐式规则将处理剩下的事情。请注意,您错误地使用pthread,您需要将pthread选项传递给预处理器和链接器,而不是lib。