You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by Harsh J <ha...@cloudera.com> on 2013/02/28 18:29:30 UTC
Re: hdfs.h C API
Hi!,
Assuming you have a "hadoop" command available (i.e. the
$HADOOP_HOME/bin/hadoop script), try to do:
export CLASSPATH=`hadoop classpath`
And then try to run your ./a.out.
Does this help?
Also, user questions may go to user@hadoop.apache.org. The
hdfs-dev@hadoop.apache.org is for Apache HDFS project
developer/development discussions alone. I've moved your thread to the
proper place.
On Thu, Feb 28, 2013 at 4:59 PM, Philip Herron <re...@gcc.gnu.org> wrote:
> Hey all
>
> I am trying to use the c api to access hdfs:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> #include <string.h>
> #include <assert.h>
>
> #include <hdfs.h>
>
> int main (int argc, char ** argv)
> {
> hdfsFS fs = hdfsConnect ("default", 0);
> assert (fs);
>
> const char * wp = "test";
> hdfsFile wf = hdfsOpenFile (fs, wp, O_WRONLY | O_CREAT,
> 0, 0, 0);
> if (!wf)
> {
> fprintf (stderr, "Failed to open %s for writing!\n", wp);
> exit (-1);
> }
>
> const char * buffer = "Hello, World!";
> tSize num_written_bytes = hdfsWrite (fs, wf, (void *) buffer,
> strlen (buffer) + 1);
> assert (num_written_bytes);
> if (hdfsFlush (fs, wf))
> {
> fprintf (stderr, "Failed to 'flush' %s\n", wp);
> exit (-1);
> }
> hdfsCloseFile(fs, wf);
>
> return 0;
> }
>
> --
>
> gcc t.c -lhdfs -lpthread -L/usr/java/default/lib/amd64/server -ljvm -Wall
>
> But i am getting:
>
> Environment variable CLASSPATH not set!
> getJNIEnv: getGlobalJNIEnv failed
> a.out: t.c:12: main: Assertion `fs' failed.
> Aborted
>
> Not sure what i need to do now to get this example working.
>
> --Phil
--
Harsh J