LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use C++ class within an .so file

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.

0 Kudos
Message 1 of 7
(3,420 Views)

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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 7
(3,373 Views)

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.

0 Kudos
Message 3 of 7
(3,327 Views)

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?

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 7
(3,316 Views)

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.

0 Kudos
Message 5 of 7
(3,302 Views)

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.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 7
(3,297 Views)

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.

0 Kudos
Message 7 of 7
(3,263 Views)