LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Failed to import the mex dll compiled by VC++ to Labview

I'm trying to get an easy function defined in .m file in Matlab imported as dll to Labview.

According to this thread, I have finished the compiling in VC++ 2008.

http://forums.ni.com/t5/LabVIEW/dll-matlab-an-LadVIEW/m-p/1420336/highlight/false#M549641

 

My system: 

Matlab 2009Rb

Visual Studio 2008

Labview 2009

 

I finally figured out the compatibility issue between Matlab 2009Rb and VS 2008 (Actually 2010 is not compatible with 2009Rb yet, I have to downgrade). Anyway I move to the phase of implementing my dll to labview. However I was stuck again.

 

My built dll file is called matlabDll2.dll, I enclosed my VS2008 project so you might help me if possible. I continue to follow your guide, but it seems the my Labview 2009 can't find some .lib files. The error from Labview is (Check the attached snapshot):

The program can't start because libmyadd2.dll is missing from your computer. Try reinstalling the program to fix this problem.

When I finished my mcc build in Matlab 2009, it gave out the following files:

libmyhadd2.dll

libmyhadd2.lib

libmyhadd2.exports

libmyhadd2.exp

libmyhadd2.ctf

libmyhadd2_mcc_component_data.c

libmyhadd2.cpp

libmyhadd2.h

Since I'm gonna compile the dll in C++ environment, so I copied 3 files: libmyhadd2.lib, libmyhadd2.dll, libmyhadd2.h to my VC project folder, however is parallel to the Debug folder.

Then I suspect it might be the path problem. So I copied the libmyhadd2.lib to Debug folder, so that the lib file is under the same folder with my output dll file, matlabDll2.dll.

OK, I configure the call function library again in labview, similar errors pop up,but not for libmyhadd2.dll file this time, instead it says:

The program can't start because mclmcr.dll is missing from your computer. Try reinstalling the program to fix this problem.

 

So I think there must be something I missed so that the labview can't find the link to other files. Any suggestion at this moment?

Arnold
Download All
0 Kudos
Message 1 of 6
(5,577 Views)

Hi Mugger,

 

I'm not sure that I am clear on what you are doing, exactly. However, it is clear that you are getting some sort of path error when you are calling a matlab-created .dll. I have a few suggestions that might help you figure out what the problem is with your path.

 

First, you might go to tools->import->shared library (.dll)... which should give you a nice set of screens to import all the functions from your .dll. I would recommend using a project, and including the dll in your project to ensure that the path is well defined.

 

Alternatively, you can add the call library function node manually, in which case I would make sure you are correctly following all of the steps in this document. I would also recommend checking the box which allows you to specify the path on the block diagram, to which you could attach a path control. This may not be acceptable for your final application, but it is something to try for troubleshooting purposes.

 

If you are trying to build an .exe, this Knowledgebase and this example may be of help.

 

Thanks,

Daniel

0 Kudos
Message 2 of 6
(5,555 Views)

It is a lot of help, still not working, 2 questions: 

1.Here is my report after following the guide of creating wrapper VIs for functions in a C/C++ DLL using the Import Shared Library Wizard.

http://decibel.ni.com/content/docs/DOC-9078

The report says:

The following errors/warnings occurred when generating the wrapper VIs for this shared library.

 
Your generated files are installed in the following folder:
E:\Sync BFP-2\Labview for BFP-2\DLL

Parsing header file warnings:
No errors/warnings occurred when parsing the header file.

The following errors/warnings occurred when generating the wrapper VIs for this shared library.

Cannot generate library
Cannot generate library. The destination folder might be defined as read-only.


VI Not Executable
The VI is not executable because of one of the following reasons:
1. The shared library or a dependent file is not installed. To make the VI executable, you must install the shared library and all support files on the computer on which you run the VI.
2. A required custom control might be empty or cannot be found. To make the VI executable, update the custom control manually.
3. The VI contains a parameter with an unsupported data type. To make the VI executable, you must replace the empty cluster that the wizard generates with a control or indicator that uses supported data types.
    matrix Add.vi
    matrix Init.vi
    matrix Terminate.vi


Here is what I did:

Step 3: In the Select Shared Library and Header File dialog (See attachment),

I input the all paths for the header files I might need to use for compiling from Matlab to VC2008

Step 5: Though the tutorial says  "We are not using any preprocessor definitions or additional include files, so leave the defaults on the Configure Include Paths and Preprocessor Definitions dialog and click Next.  " I still input some additional include files that I need. (See attachment)

 

Then I keep clicking next until it generates the project and VIs. Then I got error messages!

 

Any idea?


Arnold
Download All
0 Kudos
Message 3 of 6
(5,540 Views)

I would recommend, to start with, making sure that every single folder involved is not read only. At the very least that means the E:\Sync BFP-2 folder, desktop\testing, matlab\include and your documents\visual studio folder.

 

I would also double check that any folders being used by your labview program--that is, wherever you have you VIs stored--is also not read only. When you use that wizard, it is essentially converting the .dll you specify into a VI, and it has to put that VI somewhere, and in this case that somewhere is read only.

 

If none of those locations are read only, I would try the example dll in that tutorial and see if that works. That should narrow it down some.

 

The error messages

1. The VI will definitely not be executable, because the call lib func node is not pointing anywhere.

2. Double click on this message--it should let you know where the error is occurring. I personally have never seen that one before. It sounds like you made a control with custom features, like making it a type def, and then you saved it as a ___.ctl file, which labview cannot find anymore. But, that could be wrong.

3. If your add function is looking for two dbls and you give it two bools, you would get this error. Take a look at your controls and see if that is the case. It may also be related to #2 above, if the missing control is the input for your library node.

 

Good luck,

D Smith

0 Kudos
Message 4 of 6
(5,516 Views)

Some updates, I succeeded in calling the Matlab dll in the Visual C++ 2008. But I couldn't import my dll into Labview 2009. Every time when I do it, it gave me a error: "the program can't start because mclmcrrt71.dll is mising from your computer, Try reinstalling the program to fix this problem."

 

I checked the matlab help, they say it is because the version of Matlab compiler is not compatible. But I am pretty sure that I installed the MCR and I have succeeded in calling the Matlab dll in Visual C++ 2008. It should not be a problem.

 

Then I tried the Import Wizard method described in this thread again:

http://decibel.ni.com/content/docs/DOC-9078

 

However a different error report:

 

Your generated files are installed in the following folder:
C:\Users\Arnold Ju\Desktop\LabviewTry

Parsing header file warnings:
No errors/warnings occurred when parsing the header file.

The following errors/warnings occurred when generating the wrapper VIs for this shared library.

VI Not Executable
The VI is not executable because of one of the following reasons:
1. The shared library or a dependent file is not installed. To make the VI executable, you must install the shared library and all support files on the computer on which you run the VI.
2. A required custom control might be empty or cannot be found. To make the VI executable, update the custom control manually.
3. The VI contains a parameter with an unsupported data type. To make the VI executable, you must replace the empty cluster that the wizard generates with a control or indicator that uses supported data types.
    matrix Init.vi

Arnold
0 Kudos
Message 5 of 6
(5,486 Views)

Hey mugger,

 

To those errors, the problems seem to be the same as before. You need some sort of control cluster for the DLL which it is not finding. Double click on the error and it will take you to the problem node.

 

As to the mclmcrrt71.dll error, it is possible that your constructed .dll is referencing that dll, but now that you imported it into your labview VI it can't find it anymore. One possibility is to do a search on your system for the mclm....dll and move that to the \desktop\LabviewTry folder and see if it can find it. Past that, you may have to go back in to your dll and find out where it is referencing mclmcrrt71.dll--then you can change that directory to one more accessible.

 

If this doesn't work, before you post again you should try searching the web for other problems with this dll, and if you do need to post again please include a bit more information about how and why you are calling these dlls.

 

Thanks,

D Smith

0 Kudos
Message 6 of 6
(5,462 Views)