Academic Hardware Products (myDAQ, myRIO)

cancel
Showing results for 
Search instead for 
Did you mean: 

error with call library function node and c

Solved!
Go to solution

HI

I am trying to use call library function node for a robot control project.

Before doing the main job I tried to use the dll file in NI tutorial to see how it works.
I used the DLL file in the attachment of "Building a DLL with Visual C++" tutorial and set up the call library node.
But when I want to run the simple VI I got the following error:
"LabVIEW: (Hex 0x436) Failed to load shared library EasyDLL.dll:GetSphereSAandVol:C . Ensure that the library is present on the RT target. Use either MAX to install NI software or FTP to transfer custom libraries to the RT target."

 

I do not understand what is the error. I s there any ideas to help?
Best
Farshid

0 Kudos
Message 1 of 12
(5,293 Views)

Hi again

Here is the C program I use. It is so simple and compiles well.

// dllmain.cpp : Defines the entry point for the DLL application.

#include <windows.h>
#include "extcode.h"
// extern "C" forces the compiles to compile the function in C
// __declspec(dllexport) exports the function as DLL or to DLL
// __cdecl is the function calling convention
extern "C" __declspec(dllexport) int32_t __cdecl Multiply(int32_t a, int32_t b);

// this code is related to DLL, do not touch it.
/*
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
*/
// end of do not thouch code
__declspec(dllexport) int32_t __cdecl Multiply(int32_t a, int32_t b);
{
int32_t c;
c = a * b;
return c;
}

0 Kudos
Message 2 of 12
(5,236 Views)

Also I tried the above code with int datatype (without extcode.h) and it did not help.
The message that I get after running the VI  is :
Deploying call_library_test.vicall_library_test.vi loaded with errors on the target and was closed.
Deployment completed with errors.

 

0 Kudos
Message 3 of 12
(5,232 Views)

The VI is also attached.

0 Kudos
Message 4 of 12
(5,231 Views)

Hi all

This is an update.
I found out if I use the dll on my PC (not the myRIO) everything works fine.
Therefor I guess the problem is with real-time target.
The error I get says: "LabVIEW: (Hex 0x436) Failed to load shared library test.dll:multiply:C . Ensure that the library is present on the RT target"
Based on the error message, I think the problem is that header files/libraries that the C program uses should be loaded on myRIO.
My question is how to do this.
As far as I searched through ni website, I found a link "https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019N4SSAU&l=en-US"
but it wasn't helpful.
Best

0 Kudos
Message 5 of 12
(5,198 Views)
Solution
Accepted by topic author farshid_asadi

Hi all

I found the answer to this.

A DLL is usable in windows, so the call library function node works good with DLL if we run the code on PC.
However since myRIO is run on Linux, so we need to produce the right file for linux (.so).

0 Kudos
Message 6 of 12
(5,186 Views)

Hi,

 

If you succeeded in using call library function in MyRio if yes means please provide me a procedure how to create compatible Linux (.so) files to the My Rio and how to execute in realtime also Please do needful.

0 Kudos
Message 7 of 12
(5,110 Views)

Hi
First install eclipse and set it up as described in this tutorial:
http://www.ni.com/tutorial/14625/en/
In step 4.7 of this tutorial you need to choose "shared library>>empty project" instead of what is described.
Also in step 5.10 add "C:\build\17.0\arm\sysroots\cortexa9-vfpv3-nilrt-linux-gnueabi\usr\include" this path, it is forgotten in tutorial.

In your C code the function that you want to be used from .so file needs to be declared and defined as the following line:
extern "C" __attribute__((visibility("default"))) void example_fun(int a, int b, int* out);

\\ comment: extern "C" forces compiler to compile for C, this is needed since labview supports C not C++

\\ comment: __attribute__((visibility("default"))) this needs to be added to make the function visible in .so file

\\ it is equivalent to __declspec(dllexport) in windows programs.
extern "C" __attribute__((visibility("default"))) void example_fun(int a, int b, int* out){

    *out = a + b;
}
after you wrote the code choose Project>>Build all, and you will see that libname.so file is produced in debug folder.

Copy the libname.so file  to the following path in my rio as described in the above tutorial, "usr/local/lib/".

Now in labview open call library function node.

configure it as the following:
Function tab:
1- in library name or path add this: "usr/local/lib/libname.so".2- in function name add: "example_fun" which is name of our function. (if it was dll file labview were able to detect this automatically).
3- In calling convention use "C".

4 - In Thread use: any thread.
Parameters tab:
add all inputs and out puts and adjust them as needed.
Now you are finished with call library function.
Click ok and you can use it in labview.
If you function has arrays , for 1D arrays, when adding inputs in labview call library function you also need to add dummy inputs that specify the size of arrays and specify them in labview.
For 2D arrays I was not able to manage to work with them, So I reshaped my multidimensional arrays to 1D and then reshaped them back in labview.
I hope this helps you.
If I find time I will make a youtube tutorial for this, since it took one week from me to manege to work with it, for some silly problems.
If you had any other questions feel free to comeback here.
Best

 

 

0 Kudos
Message 8 of 12
(5,098 Views)

Thank you for your valuable response

 

I have one doubt actually am using labview2015 and now i installed 2014 C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition 2014-2016. can i change this to C/C++ Development Tools for NI Linux Real-Time, Eclipse Edition 2017-2018? or i have to follow the same steps what you mention in the tutorial instead i refer 2014 other than 2017.

i already have c source code and supporting header files and c files how i have to make this to work in myrio actually i tried a lot am not able to execute and even i am getting an error while building.

if needs i am ready to send the source codes to your email for that please give mail id.

Thank you

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

Hello,

 

Thanks to all now am able to compile and run my so files in myrio with 2014 eclipse.

 

Thanks to everyone for your time to give valuable inputs.

0 Kudos
Message 10 of 12
(5,077 Views)