编译:
g++ hello_world.cpp -I${HADOOP_HOME}/include -L${HADOOP_HOME}/lib/native -lhdfs -L${JAVA_HOME}/lib/server -ljvm
最终运行Java程序,所以不仅需要hdfs的动态库,还需要jvm的库
我安装的是openjdk11,11之后的版本取消了jre目录,重新整改了目录结构
运行报错无法挂载动态库
- error while loading shared libraries: libjvm.so: cannot open shared object file: No such file or directory
- error while loading shared libraries: libhdfs.so.0.0.0: cannot open shared object file: No such file or directory
解决办法:
- 添加动态链接库到
/etc/ld.so.conf.f
中
vim /etc/ld.so.conf.d/hdfs.conf
java的动态链接库路径$JAVA_HOME/lib/server
libhdfs的动态链接库路径$HADOOP_HOME/lib/native
(改成自己的目录就是了)
- 执行命令:
ldconfig -v