Operating System - OpenVMS
1830060 Members
2743 Online
109998 Solutions
New Discussion

Re: Problem Calling Function from Shared Image

 
Malav
Occasional Contributor

Problem Calling Function from Shared Image

Hi

I have created a shared image in VMS and while trying to call dlsym I m getting the error " %LIB-E-KEYNOTFOU, key not found in tree "

Below is the code i m using:

int main(int argc, char* argv[])
{
void* lib_handle;
void (*lib_func);
const char* error;

lib_handle = dlopen("mylib", RTLD_LAZY);
if (!lib_handle) {
fprintf(stderr, "Error: %s\n", dlerror());
exit(1);
}
lib_func = dlsym(lib_handle, "test_function");
error = dlerror();
if (error) {
fprintf(stderr, "Error: %s\n", error);
exit(1);
}
//(*lib_func)();
dlclose(lib_handle);

return 0;
}

Can some tell me where i m going wrong??

Regards
Malav
5 REPLIES 5
Bojan Nemec
Honored Contributor

Re: Problem Calling Function from Shared Image

Malav,

Welcome to the OVMS forum.

The functions dlopen,dlsym and dlclose are new from version 7.2. They are wraped around the LIB$FIND_IMAGE_SYMBOL rtl function.

When you receive the %LIB-E-KEYNOTFOU that means that there is no such function in the shareable image. Have you properly linked the shareable image? For yours example the command will be something like this:

$ LINK/SHAREABLE=mylib.exe mylib.obj, -
SYS$INPUT/OPT
symbol_vector=(test_function=procedure)


Bojan
Martin Vorlaender
Honored Contributor

Re: Problem Calling Function from Shared Image

Hi Malav,

if you didn't compile the files /NAMES=AS_IS that went into the shareable image, I'd expect the C compiler to uppercase all names.

HTH,
Martin
Bojan Nemec
Honored Contributor

Re: Problem Calling Function from Shared Image

Maybe another helpful tool. Do an:
ANALIZE/IMAGE mylib.exe/GST
to check which global symbols are defined. At the end of the listing you will receive the GLOBAL SYMBOL DIRECTORY with symbol names.

Bojan
Malav
Occasional Contributor

Re: Problem Calling Function from Shared Image

Hi,

Thanks Bojan for ur reply...

"ANALIZE/IMAGE mylib.exe/GST" helped me out. Actually found out that in the opt file instead of using the procedure name, we got to use the "real" name.. which can be found from the " cxx$demangler_db." file.

so instead of using

symbol_vector=(test_function=procedure)

-- where test_function is the actual function name

we got to use.
symbol_vector=(=procedure)

Regards
Malav
Martin Vorlaender
Honored Contributor

Re: Problem Calling Function from Shared Image

Of course, it would have been a useful detail to know that your source files were C++ ...

See http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=718061

cu,
Martin