compile error while using dlopen


 
Thread Tools Search this Thread
Top Forums Programming compile error while using dlopen
# 1  
Old 03-15-2006
compile error while using dlopen

Hi unix lovers,

I am getting error while compile a function which uses dlopen.

My code is
Quote:
$ cat testjvm.c
#include<stdio.h>
#include <dlfcn.h>
#include <link.h>


void main()
{

int retval=0;
retval = (int)dlopen("libjvm.so",RTLD_LAZY);
if(retval == 0)
printf("\nFailed to load JVM Library");
else
printf("\nSuccessfully loaded JVM Library");

}
I am getting error as follows
Quote:
$ cc testjvm.c
Undefined first referenced
symbol in file
dlopen testjvm1.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
ld: fatal: Symbol referencing errors. No output written to a.out
$
Am I missing something? I think I am missing a lot :-)

I am using solaris.

Thanks in advance,
-Ashish
# 2  
Old 03-16-2006
I have made few changes in test program. Added errorno and dlerror() just for error checking
Quote:
$
$ cat testjvm2.c
#include <stdio.h>
#include <errno.h>
#include <dlfcn.h>

void main(void)
{

void *handle;

handle = dlopen("libjvm.so", RTLD_LAZY);
if( handle == NULL )
{
printf("errno[%d], errmsg[%s]\n", errno, dlerror());
return;
}
else
{
printf("\nJVM loaded successfully");
}
dlclose(handle);

}
$


when I compile the program I get error

Quote:
$ cc -o testjvm2 testjvm2.c
Undefined first referenced
symbol in file
dlopen testjvm2.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
dlclose testjvm2.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
dlerror testjvm2.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
ld: fatal: Symbol referencing errors. No output written to testjvm2
$
Quote:
$ uname -a
SunOS snvi003 5.8 Generic_117350-20 sun4u sparc SUNW,Sun-Fire-V240
$

any pointers why the linking error?

-Ashish
# 3  
Old 03-16-2006
Quote:
Undefined first referenced
symbol in file
dlopen testjvm2.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
dlclose testjvm2.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
dlerror testjvm2.o (symbol belongs to implicit dependency /usr/lib/libdl.so.1)
ld: fatal: Symbol referencing errors. No output written to testjvm2
Then you must link it explicitly with dl, try
Code:
 cc -o testjvm2 testjvm2.c -ldl

# 4  
Old 03-16-2006
Thanks a lot andryk. It worked on solaris.

I tried the same program on hp-ux.
On hp-ux it fails to load jvm library.
Quote:
$
$ cc -o testjvm testjvm.c
$
$ testjvm
errno[0], errmsg[Can't open shared library: libjvm.sl]
$
$ echo $SHLIB_PATH
/opt/weblogic810sp3/jdk142_03/jre/lib/PA_RISC/server:/crmusr1.pi004/users/cluser/ruchit/clarify/orion01/ClarifyCRMApplications/bin:.:/oravl01/oracle/9.2.0.5/lib32:/usr/lib:/opt/tuxedo/lib:/opt/weblogic810sp3/jdk142_03/jre/lib
$
$ echo $LD_LIBRARY_PATH
/opt/weblogic810sp3/jdk142_03/jre/lib/PA_RISC/server:/crmusr1.pi004/users/cluser/ruchit/clarify/orion01/ClarifyCRMApplications/bin:.:/oravl01/oracle/9.2.0.5/lib32:/usr/lib:/opt/tuxedo/lib:/opt/weblogic810sp3/jdk142_03/jre/lib
$
$ uname -a
HP-UX hppi004 B.11.11 U 9000/800 1834916430 unlimited-user license
$
Any pointers why it is failing on hp-ux?


-Ashish
# 5  
Old 06-29-2006
Use +z option

hi ,
In Hp-Ux , when creating a shred lib we have to use +z option to create an object file for shared lib ,
for ex:
$cc +z -c share.c -o share.o

$ld -b share.o -o share.sl ( to create a shared lib )


Just try this and let me know !


Thanks
Narendra
# 6  
Old 06-29-2006
Hi Narenadra,
I am not creating shared library. I am just opening it in my program with statement
retval = (int)dlopen("libjvm.sl",RTLD_LAZY);

-Ashish
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Slackware

Error compile NFS

Tryng to compile nfs-utils to latest packages but.. make: Entering directory `/tmp/nfs-utils-1.2.8/utils/gssd' /bin/sh ../../libtool --tag=CC --mode=link gcc -Wall -Wextra -Wstrict-prototypes -pipe -O2 -fPIC -I/usr/kerberos/include -I/usr/kerberos/include -O2 -fPIC -ltirpc -o gssd... (4 Replies)
Discussion started by: Linusolaradm1
4 Replies

2. Ubuntu

Kernel compile error

Hi I'm compiling a real-time kernel in linux, but after I type make bzImage things end with this: (Things going well doing CC and things).... CC arch/x86/kernel/kgdb.o CC arch/x86/kernel/vm86_32.o CC arch/x86/kernel/early_printk.o CC arch/x86/kernel/ipipe.o... (2 Replies)
Discussion started by: mdop
2 Replies

3. UNIX for Dummies Questions & Answers

Compiling gcc to compile make to compile yaboot

I have just installed OpenBSD on a 333MHz PPC iMac G3. It has a 6GB HDD that has been partitioned as 1GB MacOS 8.5.1, 3GB MacOS X 10.3.9, 2GB OpenBSD 4.8. I now need to install a bootloader so that my computer can recognize the OpenBSD partition at startup. I have been trying to install... (0 Replies)
Discussion started by: t04st3r
0 Replies

4. Solaris

Samba 3.5.4 compile error

Hello! I am trying install samba 3.5.4. and following this instruction from the source package. So, there are my steps: 1 cd ../samba-3.5.4/source3 2 ./configure (without any arguments) and when i run make it returns error .................................................... Compiling... (2 Replies)
Discussion started by: zhum
2 Replies

5. Programming

dlopen help

//foo.c #include<stdio.h> int pen(int a) { printf("%d",a); } $cc -c foo.c $ls -shared -o libfoo.so foo.o ///////////now libfoo.so formed //i have already designed libfoo.so //main.c #include<stdio.h> #include <dlfcn.h> int main() { (2 Replies)
Discussion started by: lookforlohith
2 Replies

6. Programming

C compile error

hello can anyone help? :confused: i make a C code in FreeBSD 5.4 and it succeed to run the program requires connection to mysql server when i try to compile it under solaris i get this error message ld: fatal: file ./lib/libmysqlclient.so: wrong ELF machine type: EM_386 why? and how to... (3 Replies)
Discussion started by: kuampang
3 Replies

7. Programming

compile error message

i was trying to compile a c program and got the error below. i need help on how to resolve this $ make -ef putput `if ; then echo getinf.awk ; else echo getora.awk;fi` EI.sql `if ; then echo esql -static ; else echo esqlo8i;fi` -O -I. -c EI`if ; then echo .ec; else echo... (4 Replies)
Discussion started by: putput
4 Replies

8. Programming

Compile error

Dear All I have a program writen in C and test in Unix. Now, I am try to run this program in windows 2000. I am receiving an error ]_getopt is not define. I will appreciate if any one can help explain to me why this problem is hapening and to slove this problem. Thank you (9 Replies)
Discussion started by: coulio
9 Replies

9. Programming

resolve_symbols: loader error: dlopen:

when i try to run an executable i got the following error message: resolve_symbols: loader error: dlopen: what does this error mean and what should be done to avoid this? with regards (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies

10. Programming

Error in compile C by gcc

Hi all, I compile my c program and get following result hrnpfc01.c:1387: stray '\' in program hrnpfc01.c:1387: parse error before `,' hrnpfc01.c:1388: stray '\' in program hrnpfc01.c:1388: parse error before `,' hrnpfc01.c:1396: stray '\' in program hrnpfc01.c:1396: parse error before... (4 Replies)
Discussion started by: zico
4 Replies
Login or Register to Ask a Question