c++ - 从 c++ 使用 hadoop HDFS,未定义对 `hdfsConnect' 的引用

标签 c++ hadoop hdfs hadoop2

有没有人使用 hadoop 2.6.0 从 c++ 成功使用 hdfs?

我正在尝试编译这段代码:

#include "hdfs.h"

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

    hdfsFS fs = hdfsConnect("default", 0);
    const char* writePath = "/tmp/testfile.txt";
    hdfsFile writeFile = hdfsOpenFile(fs, writePath, O_WRONLY|O_CREAT, 0, 0, 0);
    if(!writeFile) {
          fprintf(stderr, "Failed to open %s for writing!\n", writePath);
          exit(-1);
    }
    char* buffer = "Hello, World!";
    tSize num_written_bytes = hdfsWrite(fs, writeFile, (void*)buffer, strlen(buffer)+1);
    if (hdfsFlush(fs, writeFile)) {
           fprintf(stderr, "Failed to 'flush' %s\n", writePath);
          exit(-1);
    }
    hdfsCloseFile(fs, writeFile);
}

这是我的文件夹列表:

$ ls ${HADOOP_HDFS_HOME}
bin  etc  include  lib  libexec  LICENSE.txt  logs  NOTICE.txt  README.txt  sbin  share

$ ls ${HADOOP_HDFS_HOME}/include
hdfs.h  Pipes.hh  SerialUtils.hh  StringUtils.hh  TemplateFactory.hh

$ ls ${HADOOP_HDFS_HOME}/lib/native
libhadoop.a  libhadooppipes.a  libhadoop.so  libhadoop.so.1.0.0  libhadooputils.a  libhdfs.a  libhdfs.so  libhdfs.so.0.0.0

我正在尝试使用此命令进行编译,但出现错误:

g++ -I${HADOOP_HDFS_HOME}/include -L${HADOOP_HDFS_HOME}/lib/native -lhdfs -lhadooputils -o hdfs_test hdfs_test.cpp
/tmp/ccyYER8m.o: In function `main':
hdfs_test.cpp:(.text+0x1b): undefined reference to `hdfsConnect'
hdfs_test.cpp:(.text+0x8f): undefined reference to `hdfsOpenFile'
hdfs_test.cpp:(.text+0xe8): undefined reference to `hdfsWrite'
hdfs_test.cpp:(.text+0xfe): undefined reference to `hdfsFlush'
hdfs_test.cpp:(.text+0x141): undefined reference to `hdfsCloseFile'

我知道我应该链接一些 hadoop 库,但我找不到任何文档。另外,我在 C++ 方面没有太多经验。

最佳答案

试试这个:

导出 HADOOP_INSTALL=/home/james/Desktop/hadoop2.7.2 导出 PATH=$PATH:$HADOOP_INSTALL/bin

添加链接器设置: -lhadooppipes -lhadooputils

添加链接器搜索目录: /库/ native

顺便说一句: 如果你在 64 位系统中工作,则需要为 64 位编译 hadoop。

关于c++ - 从 c++ 使用 hadoop HDFS,未定义对 `hdfsConnect' 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30435996/

相关文章:

c++ - 嵌套 map 将第二个键检测为重复

c++ - 具有多个 gl_Position 输出的 OpenGL 多渲染目标

hadoop - 无法通过增量lastmodified合并part-m-0000 *

hadoop - MRUnit 不适用于 MultipleOutputs

java - 使用 hadoop-mapreduce-examples-2.7.7.jar 时出错

c++ - CMake 错误 "Expected a command name"

c++ - 逐行读取具有不同行长的整数

hadoop - NameNode如何识别特定文件复制是设置值,而不是配置的复制3?

hadoop - 我需要帮助在Windows 7中安装hadoop

hadoop - HDFS 追加到 SequenceFile 很慢