10-16-2014 09:45 AM - last edited on 12-31-2024 01:58 PM by Content Cleaner
I tried already these Tutorials and Advices but I didn't find a solution:
- https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YHR7CAO&l=en-US
- https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000YGvGCAW&l=en-US
- https://forums.ni.com/t5/LabVIEW/Shared-Library-on-myrio-Linux-Real-time-system/m-p/2842540
- 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
screenshot2
screenshot3
screenshot4
screenshot5
screenshot6
screenshot7
10-20-2014 02:40 AM
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
screenshot 9
10-20-2014 05:04 AM - edited 10-20-2014 05:05 AM
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
10-20-2014 05:57 AM
Thank you it works!!
11-05-2014 12:32 PM
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?
11-05-2014 12:35 PM
@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).
11-05-2014 12:51 PM
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; }
11-05-2014 01:21 PM
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.
11-05-2014 03:51 PM
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.
11-05-2014 04:57 PM
Thanks, it worked definiing the extern C before the namespace.
Best regards