LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to call Fortran .dll file that using other library files?

Hi,

 

I am trying to do some arkward tasks using LabView, and I am desperately need help....

 

 A little bit background:

1. My co-worker has some code written in Fortran, where he called other libraries (many from CERNLAB or PAW). Those stuffs are pretty powerful in mathmatical calculation and simulations.

 

2. In some of my LabView code, I need to call his Fortran source code in order to do some complicated calculations. I have no capablility to translate his Fortran code to Labview (or is it even possible??), so we end up with trying to use "Call library function node" where I just provide input/outputs to communicate with his code. The idea sounds simple enough?

 

3. We complie the Fortran code into .dll, and then specifiy the dll in "Call library function node". The first try with a very simple Fortran code, something like c = a+b*a, was sucessful. The dll file and Call lib function worked good. It's sort of proved the concept.

 

4. Now I am trying more complicated Fortran code (say Test.dll), which calling other library (.lib files) that using typical "call xxx(a,b,c)" line, and my nightmare started....  It seems nothing was excuted when I call Test.dll in LabView.

 

Questions:

1. How do LabView know if the Test.dll code needs functions from other .lib files? Do I need to copy all the .lib files to a specific folder?

 

2. When I create .dll file, for LabView to be able to use it, are there any special requirement on the way the .dll is compiled?

 

3. Seems there is mismatch btw the data type in Fortran and LabView. For example, LabView's  Signed 8-bit Integer seems different with a integer in Fortran. How can i know the correlation btw data type in different langurage, i.e. LabView vs Fortran?

 

4. Are there any good examples that I can take a look?

 

 

I would highly appreicate any suggestions/helps!

 

Rgds,

 

Harry

0 Kudos
Message 1 of 8
(5,169 Views)

What fortran compiler are you using?

 

In intel fortran, you can set options when building the dll to include everything.

The dll will be larger, but you don't need to worry about secondary dependencies. (See also here)

Message 3 of 8
(5,145 Views)

Altenbach,

 

I am using the Compaq Virtual Fortran.

 

I tried the same Fortran code to build an excutable and everything works ok. I have a feeling that the way I set up my LabVeiw call library node probably has something wrong, but I cannot prove anything (or don't know how to)

 

Thanks

0 Kudos
Message 4 of 8
(5,143 Views)

You are aware that Intel Visual Fortran is the successor to Compaq Visual Fortran (I think you made a mistype with the Virtual)? So an upgrade might be at its place.

 

Anyhow I'm really not familiar with Fortran at all, but lib files are usually compiled into an EXE or DLL and not loaded dynamically. 1) 

So there should be no problem with locating those libs. What most likely is a problem are other DLL dependencies such as any Fortran Runtime library or possibly other third party DLLs the more advanced code in your DLL might be using.

 

Typically most compilers can be configured to link the runtime library code statically into the DLL, as altenbach reports for the Intel compiler, otherwise you must make sure to install the  redistributable Fortran Runtime Library for your compiler. Besides that you must make sure to find out what other runtime dependencies your code might have and install them.

 

1) One exception I know of is LabWindows CVI which allows to also load lib files dynamically. This is supposedly a legacy feature from LabWindows for DOS, which allowed that feature to simulate dynamic module loading in order to swap modules at runtime to work around the 640k memory limitation of DOS.

Rolf Kalbermatter
My Blog
Message 5 of 8
(5,130 Views)

All,

 

I finally got my code work today! Basically there are two main things I discovered/learned.

 

1. To include mutiple library files, you need to specify them in the Link Input option of the project. Only a space can be used to seperate librarys from each other. No comma or semicolon allowed.

 

2. Data type in LabView and Fortran must to match with each other, otherwise, although the code can be compiled/built successfully but it will not run properly. It's a pity that no any type of error report will indicate the errors, which make you think nothing happened at all.

 

3. In order to run the Labview executable along with the Dlls on a machine that has neither Labview nor Fortran compiler installed, you have to manually copy/paste several .dll files into the destination machine's installation folder. In my case I need 3 extra Dlls to be copied. I checked the CVF manual, those dlls are actually re-distributable meaning you are allowed to copy them to other machines.

 

At the moment, I just worked out a few simple routines to basically make sure it can work. Later we will start working on getting the "real" code going. I am sure I will find myself struggled here or there later on, so I'll be back to ask help from you guys for sure 🙂

 

Thanks for your help!

 

Rgds,

 

Harry

0 Kudos
Message 6 of 8
(5,117 Views)

For the LabVIEW support files you really need to install the runtime engine. Copying DLLs is not a good option.

Most compilers nowadays come with an installer or executable that installs the necessary redistributable runtime library components. Copying DLLs is again not a good option here.

 

As to data type mismatch, the DLL interface has no mechanisme to describe the parameter interface like ActiveX or .Net typelibraries with managed interfaces can.

Checking the datatypes manually and doing debugging with trial and error if you are not sure are by definition the only way to get it correct.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 8
(5,113 Views)

Yes, to get LabView excutable running on a fresh machine I did install the run-time engine.

 

We probably should get a Intel VF or sth instead of using CVF later on. It's just at the moment my coworkers are using CVF and they have no will to change to something else... 🙂

 

Thanks for your suggestions.

0 Kudos
Message 8 of 8
(5,107 Views)