LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabView Linux RT C++ .so example

The provided NI example shows how to build a .so from .c file (C code).

https://nilrt-docs.ni.com/cross_compile/build_shared_library.html

 

I've worked through the example but have trouble when trying to do the same thing for a C++ (.cpp) file.

 

Anyone have an example of a C++ shared object for use on a LabView Linux RT target. (PXI in this case)

 

Thanks!

0 Kudos
Message 1 of 5
(98 Views)

What is your problem? It doesn’t work is rather broad:

- you can’t compile or link the so file?

- the Call Library node doesn’t let you select a function in the so?

- LabVIEW gives you an error when you close the CLN configuration dialog, telling you that the shared library or one of its dependencies couldn’t be loaded?

- you can configure and run the CLN but when you execute it it produces gibberish?

- other, such as exploding computer or attack by monsters?

 

Each of these is “doesn’t work” but the possible problems and according solutions are very different!

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 5
(64 Views)

I can compile C code and C++ code with no issues; however, when placing the C++ version of .so on the Linux, the function name is always mangled and cannot be called. 

 

Using extern "C" in the code doesn't fix the issues.

 

I'm just looking for one example of C++ code and a header file that compiles into a .so that can be called from Call Library Node. 

 

So far I can only find C examples.

 

Thanks

0 Kudos
Message 3 of 5
(40 Views)

Something is wrong.

 

extern "C" is the thing that should prevent name mangling. How do you declare the function prototype for the functions you try to export?

 

 

class Base
{
public:
    virtual void Foo() = 0;
};

class Derived : public Base
{
public:
    virtual void Foo() {};
};

extern "C" Base *MyExportedFunc()
{
    Base *pb = new Derived();
    return pb;
}

 

 

For at least Microsoft C it is sufficient to add the extern "C" to the function declaration in the header file. No need to repeat it in the function implementation in the cpp file.

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 5
(35 Views)

I figured it out at least in Visual Code (windows) cross compiling for Linux Target.

 

The header file needs the extension .hh not .h and c++ code file needs the extension .cpp

 

Of course extern "C" now works as advertised.

 

Thanks! 

0 Kudos
Message 5 of 5
(26 Views)