LabVIEW Call Library Function Node Gets Function Not Found in Library Error

Updated Mar 27, 2023

Reported In

Software

  • LabVIEW Full
  • LabVIEW Base

Issue Details

I am using LabVIEW's Call Library Function Node to call a function in a shared library (DLL), but doing this results in the error "Function Not Found in Library"

Solution

  1. Make sure you spelled the function name correctly. Function names are case-sensitive.
  2. If you are calling a Windows API function that is implemented in Unicode and ANSI versions, the true function name has an "A" (for ANSI) or "W" (for Unicode) appended to the end. Generally you should call the ANSI version, but it may be necessary to consult your API documentation.
  3. Make sure the function you are trying to call was exported.
    • If you are using a third-party library, consult the documentation for that library to determine which functions are exported.
    • Ensure that you are not encountering name decoration, explained further in "Additional Information"
    • If you are not the author of the library, you must specify the exported function name in the Call Library Function Node. 
  4. Make sure you entered the actual name of the function in the library, which might be different from the name that you use to call the function from a text-based programming language. Refer to the Function Name in Library Does Not Match Function Call Name section in "Additional Information" for more information.

Additional Information

When you use the Call Library Function Node, LabVIEW requests a pointer to the desired function in the library from the operating system. This error indicates that the OS could not provide this pointer, because a function with the name you entered does not exist in the library

Function Name in Library Does Not Match Function Call Name

The common reasons for the function name in the library not matching the function name you use to call it include the following:
  • The C function name is #defined in a header file to another name that is used in the library.

  • The C function name is decorated in the library 
Function Name Is ​#defined

#defining (pronounced "pound-defining") is a process in C compilers where you substitute the #defined string for another string, the definition string. You might want to #define when more than one version of the function is available, and the choice depends on certain system properties and is decided at compile time. For example, any Win32 API function that involves strings has two versions, depending on whether the program is designed for Unicode or standard ASCII. You might try to call MessageBox, when MessageBox is #defined as MessageBoxA for ASCII calls.

To determine if this is the problem and to determine the real name of the function in the library, inspect the header (.h) file for the library. Search for the definition of the desired function. Notice in the following example code that under certain circumstances, the MessageBox is defined as MessageBoxA, and under others, it is defined as MessageBoxW. WINUSERAPI int WINAPI MessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType);
WINUSERAPI int WINAPI MessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);
#ifdef UNICODE
#define MessageBox MessageBoxW
#else
#define MessageBox MessageBoxA
#endif // !UNICODE 

Function Name Is Decorated

Certain compilers (particularly C++ compilers) build DLLs in such a way that the exported function name is not the same as the function name in the source code. This is also known as name decoration. Decoration is the process by which you add other characters to C function names in the resulting object code. The specific format of the decoration depends on the language and the calling conventions. If a function was compiled with calling conventions other than C and no export table was defined for the library, the function name might be decorated.

For example, the same function name that is used in text-based programming languages has with the following names in the library, depending on the calling convention and language:
  • Function Name: MyFunction
  • C Function, C calling conventions: MyFunction
  • C Function, stdcall conventions: _MyFunction@20
  • C++ function: ?MyFunction@@YAXHPANPADKPAF@Z
To find the name of an exported function in a library, you might need to inspect the library manually. On Windows NT, you can use the QuickView utility to list the export table for the library. If you have Microsoft Visual C++, it comes with a utility named dumpbin, which you can use with the /exports option to list the export table. Compilers on other operating systems might have similar utilities. The nm utility often works on UNIX systems.