Completing the .c File

After you build a function prototype to build a shared library from a text-based programming language, complete the .c file.

The Call Library Function Node generates the following source code skeleton in myshared.c:

/* Call Library source File */

#include "extcode.h"

int32_t avg_num(float a[], int32_t size, float *avg);

int32_t avg_num(float a[], int32_t size, float *avg)

{

/* Insert code here */

}

Replace the /* Insert code here */ spacer with the following function code, making sure to place the code within the pair of curly braces:

int i;

float sum = 0;

if(a != NULL)

{

for(i=0; i < size; i++)

sum = sum + a[i];

}

else

return (1);

*avg = sum / size;

return (0);

Required Libraries

This simple example requires the extcode.h header file for a few simple data types. extcode.h provides access to a set of LabVIEW manager functions that perform simple and complex operations, ranging from low-level byte manipulation to routines for sorting data and managing memory. When you build more complex shared libraries, you must include header files for all related libraries. For example, a Windows shared library project might need to include windows.h.

When you want to use the LabVIEW manager functions inside a shared library, you must include the labviewv.lib library file in the compiled project. This file appears in the labview\cintools directory.

You need the LabVIEW manager functions if you intend to do any of the following tasks:

Refer to the LabVIEW Manager functions for more information about the manager functions.

After you complete the .c file, build the library project in an external IDE.