The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C compile error kuampang High Level Programming 3 11-29-2006 09:30 PM
compile error message putput High Level Programming 4 10-04-2006 01:43 AM
Compile error coulio High Level Programming 9 06-30-2006 02:43 AM
resolve_symbols: loader error: dlopen: gfhgfnhhn High Level Programming 1 06-29-2006 07:08 AM
Error in compile C by gcc zico High Level Programming 4 11-11-2003 11:45 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 03-15-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
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
Reply With Quote
Forum Sponsor
  #2  
Old 03-15-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
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
Reply With Quote
  #3  
Old 03-15-2006
andryk's Avatar
Registered User
 

Join Date: Sep 2003
Posts: 448
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
Reply With Quote
  #4  
Old 03-15-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
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
Reply With Quote
  #5  
Old 06-28-2006
Registered User
 

Join Date: Feb 2006
Posts: 35
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
Reply With Quote
  #6  
Old 06-29-2006
Registered User
 

Join Date: Dec 2005
Location: Pune
Posts: 78
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
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:27 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0