Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

dlsym is not working old VMS

SOLVED
Go to solution
Alex Chupahin
Super Advisor

dlsym is not working old VMS

Hello.
There is VAX system with OpenVMS 7.2

There are three files:

*******************
TEST: shareable image
*******************
#include
test()
{
printf("test\n");
}

*******************
MAIN:
*******************
#include
#include
#include
main()
{
void *h;
void (*func);

h=dlopen("TEST.EXE",0);
func = dlsym(h,"TEST");
if (func==NULL) printf("Error\n");
}

****************
OPT.OPT
****************
UNIVERSAL=TEST


Compiling:
CC MAIN
LINK MAIN
CC TEST
LINK/SHARE=TEST TEST,TEST/OPT

RU MAIN
Error.
What I'm doing wrong?

P.S.
ANALIZ/IM shows me TEST symbol ok.
7 REPLIES
Alex Chupahin
Super Advisor

Re: dlsym is not working old VMS

Next experiment:

************************
main1
************************
#define __NEW_STARLET 1

#include
#include
#include
#include
#include
#include


/*
** Set up some macros to make the declaration of a variable string easy.
*/
#define MAX_LEN 250

#define VS_STRING(name, len) \
struct { \
unsigned short length; \
char string[len]; \
struct dsc$descriptor_vs desc; \
} name = {0, "", {len, DSC$K_DTYPE_VT, DSC$K_CLASS_VS, (char*)&name.length}}

#define STRING(name) VS_STRING(name, MAX_LEN)


main()
{
static int edit_routine;

static unsigned long int r0_status;
static unsigned int arg_list[4];

static $DESCRIPTOR (filename_d, "TEST.EXE");
static $DESCRIPTOR (symbol_d, "TEST");

static STRING (instring);
static STRING (outstring);

r0_status = lib$find_image_symbol (&filename_d, &symbol_d, &edit_routine,
0,
0);
instring.length = sprintf (instring.string, "test 1 2 3");

/*
** Set up the argument list for lib$callg(). 32 means "uppercase the
** input string". For the BASIC programmers, I'm desperate to code it
** as "32%", but I'll resist ;-)
*/
arg_list[0] = 3;
arg_list[1] = (unsigned long int)&outstring.desc;
arg_list[2] = (unsigned long int)&instring.desc;
arg_list[3] = 32;

/*
** Call the routine whose address we found.
*/
r0_status = lib$callg (arg_list,
(int (*)())edit_routine);
//errchk_sig (r0_status);

/*
** Show we really did the business. Note "test" should now be upper
** case.
*/
(void)printf ("%-.*s\n",
outstring.length,
outstring.desc.dsc$a_pointer+2);
}


It is not working too.
"invalid logical name" when call LIB$FIND_IMAGE_SYMBOL

Kris Clippeleyr
Honored Contributor
Solution

Re: dlsym is not working old VMS

Alex,
I think the shareable must be put in SYS$SHARE for LIB$FIND_IMAGE_SYMBOL to work, or use a logical name to point to the image.
Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Joseph Huber_1
Honored Contributor

Re: dlsym is not working old VMS

One thing for sure:
test the return value of dlopen(), it certainly will show NULL:
dlopen("TEST.EXE",0) will search for sys$share:TEST.EXE.
Either specify the full file specification in the dlopen call, or -better- define a logical name like
define TESTSHR sys$disk;[]TEST.EXE,
and then dlopen("TESTSHR",0);

http://www.mpp.mpg.de/~huber
H.Becker
Honored Contributor

Re: dlsym is not working old VMS

It is always goo to check the return code. But be aware, that dlopen() on VMS just creates and returns the handle. It will neither open the file nor check if it can be found anywhwere. dlsym calls lib$fis and then the file is searched for activation and accessed for the symbols. This is documented behavior.
WW304289
Frequent Advisor

Re: dlsym is not working old VMS

"
But be aware, that dlopen() on VMS just creates and returns the handle. It will neither open the file nor check if it can be found anywhwere.
"

No, Hartmut, dlopen() does more than that :-) Just run the attached program.

-Boris

x.c
---
#include
#include

#define TEST(N, IMAGE) \
if ( !dlopen(IMAGE, RTLD_LAZY) ) \
printf(#N ") %s\n", dlerror()); \
else \
puts(#N ") success");

int main() {
TEST(1, "decc$shr");
TEST(2, "decc$shrxyz");
TEST(3, "sys$login:login.com");
}
H.Becker
Honored Contributor

Re: dlsym is not working old VMS

Hi Boris,
You are right and I was wrong. I wonder how this was implemented :-) Now we need someone to fix HELP CRTL dlopen Description: "...This function does not load a shareable image but rather saves...

Hartmut
Alex Chupahin
Super Advisor

Re: dlsym is not working old VMS

Thank you very much for all, for your help.
Yesterday I find the same solution.
I've defined the name of shareable image via DEFINE and open it succesfully.

Also, shareable images should be built without ANY WARNINGS. It seems, this *bug* is in 7.3-1 and earlier.


Working since 7.3-2 that works with filenames without logical names, I forget about this feature :)