07-20-2015 05:51 AM
Hi everybody ! 🙂
Today, I'm trying to use a .so file within Labview.
I already have the source code in C++ (not written by me), containg C++ classes, struct, functions... I compiled the project with success with the gcc toolchain provided by National Instrument and generated the corresponding .so file. However I fail to reach shared object functions within Labview. I think the problem is due to C++ classes, I read some documentations about the adding of some parts of code like "extern "C"" in case of C++ classes, however all things I tried not provide any result...
So, I would like to know if a documentation about the integration within Labview of a .so file containing C++ classes is existing ?
(I precise that I have already done an integration of a very simple .so file with success (but without classes))
Thank you for your help !
Afghow.
07-20-2015 08:00 AM - edited 07-20-2015 08:07 AM
Basically you need to write a second shared library that wraps your c++ objects.
Have you done some googling? That should have given you this:
https://lavag.org/topic/9232-c-classes-from-lv/
http://labviewwiki.org/DLL/shared_library.
The second half in the last link shows what you have to do in principle.
07-22-2015 08:07 AM
Hi !
Thanks for the second link, I have wrapped my C++ classes with success, however I have some problem of calling within Labview. Everything works fine when a class is not dependant to another. But in my case I have an architecutre like that :
class A{
//Bla
}
class B{
private: A;
}
So when I want to construct an object of the class B, I have a crash of the LabView application. I think that the constructor of class B tries to call the constructor of the class A, but not the wrapped constructor. So, I don't see how to solve this problem without modifying the implementation of methods of classes, which will break the principle of a "wrapper". A wrapper just has to be a layer and doesn't have to modify the implementation.
I don't know if my explication is clear 😕
So, do you have some trick to do within the wrapper class file or a tutorial about this ?
Thank you for your help !
Afghow.
07-22-2015 08:54 AM
Since class A is a private member in class B your constructor for class B has to somewhere explicitedly new() class A, doesn't it? so why would that crash? Is your class A in yet another DLL that is not available?
07-22-2015 09:44 AM
That's that, the class B constructor calls the constructor of the class A through an initialization list. So, for you the problem is not located here ?
My class B try to access to a /dev node, maybe the problem is here. I have tested with a sample main where I have the same /dev access using same functions which are present is the so file and it's working fine.
Maybe the combo of LabView and Linux module access is the problem ? I'm lost but I'm searching, if you think having some clue, let me know.
Thank again for your reply,
Afghow.
07-22-2015 09:48 AM - edited 07-22-2015 09:48 AM
LabVIEW simply calls the shared lib using dlopen() and dlsym() so a proper test case would be to create a main() program that does this with your wrapper shared lib.
07-23-2015 09:30 AM
It's what I did and I have a segmentation fault when I'm calling the constructor of the class, and it's what it makes crash the LabView program.
I've applied the classic method to wrap the C++ class, I don't know where the problem could be. Moreover debugging this on the MyRIO board will be hell.
I continue my researches, if you have some clues...
Afghow.