11-13-2009 12:47 AM
Hi all,
Hope someone can help me with my error. I am trying to create a DLL file from my CVI project so that I can use it in LabView. The CVI project itself includes a DLL and a library (e.g. LJIF.dll and LJIF.lib). When I try building the DLL, I got the following error:
ERROR: Exporting a variable or function defined in an import library is not supported. Unable to export '_LJIF_OpenDeviceETHER@4'.
I gather that LabWindows 8.0 does not support this function. Is that right?
If so, may I ask what other ways are possible for me to use a CVI code in LabView?
I tried creating a CIN file from the CVI project but I also ran into errors that I could not resolve.
Creating a EXE from the CVI project will not be appropriate because I need to pass in parameters in and out from the EXE.
Hope to receive help soon!
11-13-2009 01:06 AM - edited 11-13-2009 01:09 AM
Hi,
It seems you cannot directly expose a function that you use from an external library.
You need to write a "wrapper function" for that purpose.
A wrapper is something like that: Suppose you want to export int func1 (double, char *) which is actually in the import library.
You create func2 in your project as follows:
int func2 (double d, char *cp)
{
return func1(d, cp);
}
So, func2 wraps func1, hence the name wrapper function. Then you should be able to export func2. You may need to mark func2 as DLLEXPORT DLLSTDCALL depending on your export settings.
Hope this helps,
11-13-2009 01:35 AM
Hi ebalci,
I do not have this option as I'm given this .dll and .lib file as it is. So I will not know what functions are there in the imported library. The header file for the library also did not contain the prototypes for the functions.
If I do not have this option of creating a DLL file, my next choice would be the CIN? I am also running into errors for this with the same CVI project, e.g.:
Undefined symbol '_CINRun' referenced in "cin.obj"
I post this up in another thread. Hope you could also assist me there?
Thanks alot really!
11-13-2009 01:41 AM - edited 11-13-2009 01:42 AM
Here is another post, that may be helpful.
I cannot understand how could you try exporting functions whose prototype you don't know?
Even if you can export them, how do you plan to use them from LV again without knowing how to call them?
What is CIN, by the way?
11-13-2009 01:50 AM
Hi,
Sorry my mistake. Managed to find the prototypes. However the same error still showed up even after I added the wrapper function.
the wrapper function is supposed to be created in the main .c file? I did this:
RC WINAPI wrapLJIF_OpenDeviceETHER(IN LJIF_OPENPARAM_ETHERNET* pOpenParam)
{
return LJIF_OpenDeviceETHER(pOpenParam);
}
The same still occurs. Did I create it incorrectly?
CIN is Code Node Interface. It is found in LabView and its used to export other programming languages like CVI into Labview.
11-13-2009 02:23 AM
Check your export settings from the menu: Build > Target Settings > Export what
This setting tells the compiler how to distinguish the functions to be exported from others.
Since you got the same error, you must still be exporting the non-wrapped version due to your export settings.
You also have to mark the wrapper function to be exported.
Hope this helps,
11-13-2009 03:17 AM
I'm sorry but I'm getting confused.
the header file has the include statements and prototype:
#pragma once
#include <windows.h>
#include <winsock.h>
#define EXP __declspec(dllimport)
EXP RC WINAPI LJIF_OpenDeviceETHER(IN LJIF_OPENPARAM_ETHERNET* pOpenParam);
---------------------------------------------------------------------------------------------------------
i created the wrapper function in the main .c file:
RC WINAPI wrapLJIF_OpenDeviceETHER(IN LJIF_OPENPARAM_ETHERNET* pOpenParam)
{
return LJIF_OpenDeviceETHER(pOpenParam);
}
So to export this wrapper function, I have to change the following statement in the header file (i.e. modifying the existing .h file):
EXP RC WINAPI LJIF_OpenDeviceETHER(IN LJIF_OPENPARAM_ETHERNET* pOpenParam);
TO:
RC WINAPI DLLEXPORT LJIF_OpenDeviceETHER(IN LJIF_OPENPARAM_ETHERNET* pOpenParam);
and include the definition:
#define DLLEXPORT __declspec(dllexport)
-------------------------------------------------------------------------------------------------------
Is this correct?
11-13-2009 07:08 AM
Did you check the Target Settings that I mentioned in my last post?
Even if you remove the EXP, the function may still being exported due to your export settings.
You can change the Export what setting to Symbols marked for export.
Only in that case, adding/removing EXP to a function prototype changes that function's export state.
Please see the export-related parts of the CVI help about Target Settings.
This issue is a little too hard to be covered completely in a post.
Note: You should also remove the DLLEXPORT token from the original function.
11-13-2009 08:08 AM
You still seem to be trying to export your imported file:
RC WINAPI DLLEXPORT LJIF_OpenDeviceETHER(IN LJIF_OPENPARAM_ETHERNET* pOpenParam);
You need to export your wrapped one:
RC WINAPI DLLEXPORT wrapLJIF_OpenDeviceETHER(IN LJIF_OPENPARAM_ETHERNET* pOpenParam);
JR
11-13-2009 05:56 PM
Hi Ebalci & JR,
Thanks alot for your advices, appreciate it. I will try the stuff you mentioned. Will get back asap for help if needed.