LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a DLL including manager support in mingw/gcc

I am writing a DLL in C (note not c++) using Mingw/gcc in the Dev-c++ environment and DO NOT want to use Microsoft Visual C++ (MSVC).
I require the ability to create/resize/delete arrays within my DLL (as I do not know the sizes required a priori) and therefore want to include the labview.lib library and the extcode.h header.

However, the supplied library is compatible with MSVC only and I get the error msgs in Dev-c++.

I've managed to compile the DLL without accessing the library routines, but when I try to access a simple function such as

typedef struct {
    int32 length;
    float data[1];
} t_LV_1DFlt, *p_LV_1DFlt, **h_LV_1DFlt;

DLLEXPORT int32 MyGetArraySize(h_LV_1dFlt hdl)
{
    return (*hdl)->length;
}

/* when commented, file compiles */
DLLEXPORT int32 MyGetHndSize(h_LV_1DFlt hdl)
{
    return DSGetHandleSize(hdl);
}

The first method compiles and works no problems (DLLEXPORT is a macro for __declspec (dllexport)).
However, the second method results in the following errors:
.drectve '-defaultlib:uuid.lib ' unrecognized
.drectve '-defaultlib:uuid.lib ' unrecognized
symbol not found
id returned 1 exit status


Is it possible to include the library with compilers other than MSVC?
0 Kudos
Message 1 of 3
(4,481 Views)
After a bit of research, I have found this forum thread which may be of some use to you:

http://forums.ni.com/ni/board/message?board.id=250&message.id=10936&page=1

Let me know if this helps,

Daniel
0 Kudos
Message 2 of 3
(4,462 Views)


@DanBrowne wrote:
After a bit of research, I have found this forum thread which may be of some use to you:

http://forums.ni.com/ni/board/message?board.id=250&message.id=10936&page=1

Let me know if this helps,

Daniel


The complication here is only that the import library should first detect if it runs inside the LabVIEW development environment LabVIEW.exe, for instance by doing a:

HMODULE gLVRTModule;

gLVRTModule = GetModuleHandle(NULL);
if (!GetProcAddress(gLVRTModule, "AZNewHandle"))
    gLVRT = GetModuleHandle("lvrt.dll");

and if that fails try to link to lvrt.dll instead.

if (!gLVRTModule)
{
   MessageBox("Link Library was  not invoked by a LabVIEW process!");
   ExitProcess(1);
}

and then use the returned HMODULE to load the function exports through.

Problem is that creating an import library that uses that custom loader is not trivial. Either you need to make above code into an object file and then cause the import library generator to call this function instead of its default function to load the DLL library and use the gLVRTModule handle to reference the function, or create a C wrapper for each function you want to call that takes this gLVRTModule handle as library handle to GetProcAddress the according function from.

The reason why NI does not support this is the fact that while everybody talks about gcc, gcc is not everywhere the same. It depends on what you use in MingW, Cygwin, or any of the other distributions, variants, etc. as to what for a import link library can and will work, and testing that with all of them is a work nobody does nor wants to do.

But reading the original error message:

.drectve '-defaultlib:uuid.lib ' unrecognized
.drectve '-defaultlib:uuid.lib ' unrecognized


It seems the labview.lib library might actually be linkable but one of the directives inside it about what defaultlib to use is not a valid directive for the used gcc linker. It's strange that a linker treats unknown directives as error instead of simply issuing a warning and continuing with the work anyhow, but maybe there is a command line option to tell it to ignore specific errors/warnings?

Rolf Kalbermatter


Message Edited by rolfk on 01-04-2008 09:52 PM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 3 of 3
(4,452 Views)