使用来自 c++ 的 hadoop HDFS,对"hdfsConnect"的未定义引用
Use hadoop HDFS from c++, undefined reference to `hdfsConnect'
是否有人使用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' %sn", 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/詹姆斯/桌面/hadoop2.7.2导出路径= $路径:$ HADOOP_INSTALL/bin
添加链接器设置-lhadooppipes-lhadooputils
添加链接器搜索目录/lib/native
顺便说一句:如果您在64位系统中工作,则需要编译64位的hadoop
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 强制转换为引用类型
- 引用一个已擦除类型(void*)的指针
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 具有默认值的引用获取函数
- 如何使用基类指针引用派生类成员
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 使用来自 c++ 的 hadoop HDFS,对"hdfsConnect"的未定义引用