gpt4 book ai didi

C++ 隐式进入/启动主要可执行错误

转载 作者:行者123 更新时间:2023-12-01 18:37:18 25 4
gpt4 key购买 nike

我在 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 $@

当我尝试编译源文件时,出现错误提示

Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [wordcount] Error 1

我不知道这意味着什么,因为我已经有了一个 main 函数。

你能解决这个问题吗?

谢谢!

最佳答案

您没有将源文件传递给配方,避免这种情况的最简单方法是仅依靠一次性程序的内置 make 规则,您所需要的只是:

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 的 makeimplicit 规则将处理剩下的事情。请注意,您错误地使用了 pthread,您需要将 pthread 选项传递给预处理器和链接器,而不是库。

关于C++ 隐式进入/启动主要可执行错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49933550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com