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