user513164
user513164

Reputation: 1858

linux library problem

Everybody out there, I'm writing a c code which have a strange problem when I compile it . The source code is OK. I compile it with following option:

$ gcc above_sample.c -I/home/hadoop/project/hadoop-0.20.2/src/c++/libhdfs -L/home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib -lhdfs  -o above_sample.

But it show the out put like that:

/usr/bin/ld: warning: libjvm.so, needed by /home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so, not found (try using -rpath or -rpath-link) /home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so: undefined reference to `JNI_CreateJavaVM@SUNWprivate_1.1' 
/home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so: undefined reference to `JNI_GetCreatedJavaVMs@SUNWprivate_1.1'
collect2: ld returned 1 exit status

I searched for libjvm.so i found It in my system in /usr/java/lib.

I made a symbolic link of it but did not work.

i copied the library in to several places like usr/lib check the LD_library_Path but could not manage to compile the program it showing the same error again and again

Can any one tell me what I'm doing wrong ? how to link .so file to gcc ? or how .so files are linked in program?

Upvotes: 4

Views: 4517

Answers (3)

Tagar
Tagar

Reputation: 14871

That's what worked for me:

CDH=/opt/cloudera/parcels/CDH
OS_ARCH=amd64

gcc hdfs_example.c -I$CDH/include -L$CDH/lib64 \
       -L/usr/java/default/jre/lib/${OS_ARCH}/server \
       -ljvm -lhdfs -o hdfs_write_test

Upvotes: 0

Alex InTechno
Alex InTechno

Reputation: 1261

Linker gives a warning about not found reference to function JNI_CreateJavaVM@SUNWprivate_1.1

/usr/bin/ld: warning: libhdfs.so: undefined reference to `JNI_CreateJavaVM@SUNWprivate_1.1'

This function name might be specific for library from Sun/Oracle HotSpot JVM. Other JVMs may have another name. For example, mine OpenJDK had only shorter name such as JNI_CreateJavaVM and linker gave me the same warning.

You may get list of the functions from your libjvm.so by running command:

readelf -s libjvm.so | grep JNI_CreateJavaVM # given that you are in catalog containing libjvm.so

If output does not contain required function, then you might want to install another JDK.

Upvotes: 2

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181270

Try adding:

-L/usr/java/lib

To your linker command, since that's the library your linker is not being able to find: I_GetCreatedJavaVMs@SUNWprivate_1.1.

A little piece of advice: it's not a good idea to mess with LD_LIBRARY_PATH. Just fix your linker command.

Upvotes: 4

Related Questions