LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I use a shared library made with the application builder?

Hi,

I am using LabVIEW 7.1 running on Slackware 10.1 (kernel 2.4.29) and I am trying to call a graph display from a C program that I use for debugging VME access from a VMIVME controler. So using the application builder I built the VI as a shared library (graph.vi -> graph.so) containing a function called "graph". In my main program the call to the dlopen fails with the error: "graph.so: undefined symbol: UninitLVClient". When I examin graph.so with nm I see that UninitLVClient and other LabVIEW functions are indeed undefined and using ldd shows that graph.so has dependencies only on libc.so.* and *linux*.so.* but not on LabVIEW related stuff. Those functions are defined in the liblv.so that's in the cintools directory but I have no idea if the user is supposed to use that.

So I think I am missing an important concept here. Can somebody help or direct me to some documentation (I found lots of information about how to link external code to LabVIEW but nothing about how to link LabVIEW code to an external program)?
0 Kudos
Message 1 of 3
(2,836 Views)
0 Kudos
Message 2 of 3
(2,819 Views)
Thanks Watermann,

your message has been very useful so now I am linking to the proper library but I still have problems when trying to load dynamically the shared library produced with LabVIEW. It is strange that I could successfully load the lvrt library at loading time but it does not work when I am loading the library at execution time.

I made a small LabVIEW program that prints a hello window and I am calling it from a C program. In the first program main.c I am linking to the lvrt library at loading time and it works but in the second one I am linking dynamically at execution time and it does not work. For my work I need to be able to load code done in LabVIEW at execution time. Any help is appreciated!

Program main.c:

// small program to call a LabVIEW shared library

#include
#include
#include "hello.h" // got this from the LabVIEW builder, i.e. when I made the hello.so

int main(void)
{
printf("Hello from C!\nLets call LabVIEW now\n");
hello();
printf("Bye ... \n");

return 0;
}

The command to compile main.c, i.e. linking shared library lvrt when loading main program:
gcc -Wall -I /usr/local/lv71/cintools/ -o main main.c hello.so -l lvrt
The LD_LIBRARY_PATH has been defined and exported:
$ LD_LIBRARY_PATH=$PWD
$ export LD_LIBRARY_PATH
IT WORKS!

Program main2.c:

// small program to call a LabVIEW shared library

#include
#include
#include

int main(void)
{
void * h_lvrt;
void * h_hello;
void (* hello)(void);
char * error;

printf("Hello from C!\nLets call LabVIEW now\n");
// open LabVIEW RunTime shared library
// in my computer located at /usr/local/lib/liblvrt.so
h_lvrt = dlopen("/usr/local/lib/liblvrt.so", RTLD_NOW);
// check for error
error = dlerror();
if (error) {
printf("error : could not open LabVIEW RunTime library\n");
printf("%s\n", error);

return 1;
}
// open hello shared library
// in my computer located at /home/darss/lv_call/hello.so
h_hello = dlopen("hello.so", RTLD_NOW);
// check for error
error = dlerror();
if (error) {
// close LabVIEW RunTime shared library
dlclose(h_lvrt);
printf("error : could not open hello library\n");
printf("%s\n", error);

return 1;
}
// get function hello from library hello.so
hello = dlsym(h_hello, "hello");
// check for error
error = dlerror();
if (error) {
// close hello shared library
dlclose(h_hello);
// close LabVIEW RunTime shared library
dlclose(h_lvrt);
printf("error : could not get the hello function\n");
printf("%s\n", error);

return 1;
}
// call hello function
hello();
// close hello shared library
dlclose(h_hello);
// close LabVIEW RunTime shared library
dlclose(h_lvrt);
printf("Bye ... \n");

return 0;
}

The command to compile main2.c, i.e. dynamically linking library lvrt at execution of main2 program:
gcc -Wall -o main2 main2.c -l dl
The LD_LIBRARY_PATH still defined and exported.
IT DOES NOT WORK!
Program output:
Hello from C!
Lets call LabVIEW now
error : could not open hello library
/home/darss/lv_call/hello.so: undefined symbol: WaitLVDLLReady
0 Kudos
Message 3 of 3
(2,792 Views)