LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a c++ shared library (.so) for linux real time (for myRio) with Eclipse to use in LabView?

I tried already these Tutorials and Advices but I didn't find a solution:

http://www.ni.com/tutorial/14625/en/

http://www.ni.com/tutorial/14690/en/

http://forums.ni.com/t5/LabVIEW/Shared-Library-on-myrio-Linux-Real-time-system/m-p/2842540/

http://forums.ni.com/t5/LabVIEW/How-to-create-shared-library-for-linux-real-time-target-in/m-p/28218...

- and some more

 

I want use c++ codes on linux real time. For testing reasons I want to have a function that adds 2 values and gives the result.

 

I've done these steps:

1. writing a c++ file in Eclipse (see screensot 2)

2. building a shared library (.so) from my c++ project in Eclipse (with Cross GCC)

3. putting this file on myRio (path: /usr/local/lib/)

4. creating a VI that calls this library from Labview with a "Call Library Function Node" (see screenshot3)

5. Setting the properties for the "Call Library Function Node" (see screenshots 4-7)

 

After I run this VI i get this error message: LabVIEW:  (Hex 0x627) The function name for the ... node cannot be found in the library. To correct this error, right-click the Call Library Function Node and select Configure from the shortcut menu. Then choose the correct function name. (see screenshot1)

 

I've tried a lot things to solve this problem but I couldn't find a solution. Would be very happy if anyone can help me. I guess that I have to edit my c++ code to export my function (symbol). But I have no idea how to make it. I also tried it with a dll file in the same folder but it didn't help.

 

Perhaps someone can send an example which works on myRIO.

Thanks!

 

screenshot1

screenshot1.png

 

screenshot2

screenshot2.png

 

screenshot3

screenshot3.png

 

screenshot4

screenshot4.png

 

screenshot5

screenshot5.png

 

screenshot6

screenshot6.png

 

screenshot7

screenshot7.png

0 Kudos
Message 1 of 12
(9,278 Views)

I finally found the solution. It was because of the decorations (mangling) of the function (symbol).

 

It's eplained here: http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B

 

I solved the problem with copying the compiled shared library (libTest.so) to my Ubuntu system and running following command in the terminal (see screenshot8):

nm -D libTest.so

 

This command shows me all exported functions (symbols). As you can see it in the screenshot8 there is a function called "_Z8AddierenddPd" instead of "Addieren". I copied this name to Labview (see screenshot9) and it worked.

 

I'm sure that there is a way to compile the shared folder with gcc without decorations (mangling). But I don't know how. If someone has a recommendation I would be very glad!

 

screenshot 8

screenshot8.png

 

screenshot 9

screenshot9.png

0 Kudos
Message 2 of 12
(9,214 Views)

 can see it in the screenshot8 there is a function called "_Z8AddierenddPd" instead of "Addieren". I copied this name to Labview (see screenshot9) and it worked.

 

I'm sure that there is a way to compile the shared folder with gcc without decorations (mangling). But I don't know how. If someone has a recommendation I would be very glad!


Prepend each function declaration that you want to be available without name decoration with

 

extern "C" <your function declaration>

 

Or if you have multiple functions you want to export you can in the header file where you declare your functions simply use:

 

#ifdef __cplusplus
extern "C" {
#endif

<all your function declarations>

#ifdef __cplusplus
}
#endif

 

Rolf Kalbermatter
My Blog
Message 3 of 12
(9,201 Views)

Thank you it works!!

0 Kudos
Message 4 of 12
(9,194 Views)

Hello, I had the same problem and followed the advice of including the 

 

extern C { }

 

in the function prototype definition however the same problem happens and GCC changes the name of the function. 

 

Any other leads in this problem? 

0 Kudos
Message 5 of 12
(9,012 Views)

@jdlara wrote:

Hello, I had the same problem and followed the advice of including the 

 

extern C { }

 

in the function prototype definition however the same problem happens and GCC changes the name of the function. 

 

Any other leads in this problem? 


Show your code! Most likely you made an error  (or maybe you are using a super duper new GCC version with some bugs, but that is much less likely).

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 12
(9,010 Views)

HI, thanks for the reply. I am using Eclipse with the gcc compiler provided by NI for the cRIO 9068. Here is the code, I made the same test with the command nm -D directly on the cRIO and the compiler is mangling with the function name Multiply as shown in the picture:

 

 

// aritmethic test.cpp : Defines the exported functions for the DLL application.
//

#include <iostream>

using namespace std;

#ifdef __cplusplus
extern "C"{
#endif

int Multiply(int a, int b, int *x1, int *x2);

#ifdef __cplusplus
}
#endif

int main ()
{
	}

int Multiply(int a, int b, int *x1, int *x2)
{
	*x1= a*b;
	*x2 = a*a + b;
	return 0;
}

 

window.tiff

 

0 Kudos
Message 7 of 12
(9,007 Views)

Most likely you need to put the extern "C" declarations before defining any namespace. Not sure if extern "C" should have higher precedence than a namespace declaration but under GCC it seems not.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 12
(8,997 Views)

The C compiler logically can't disable name mangling in a namespace. So yes you really need to put the extern "C" declarations before any namespace declarations. In older GCC versions such order was simply ignored (extern "C" had no effect). Newer versions should give you at least a warning if not an error, provided you define a high enough warning level.

Rolf Kalbermatter
My Blog
Message 9 of 12
(8,985 Views)

Thanks, it worked definiing the extern C before the namespace. 

 

Best regards 

0 Kudos
Message 10 of 12
(8,976 Views)