Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Exporting Fortran data to mat file

Kami_M_
Beginner
1,282 Views

Hi,

I am trying to create mat file from Fortran data using Matdata.

It needs libmat.lib, libmx.lib from Matlab library and libmat.dll and libmx.dll from Matlab bin directories. On the command line mode, where I set PATH and LIB of these files*, everything is OK. But when I am trying to run it from VS shell in the form of VF project, I get fatal errorLNK1107: invalid or corrupt file for dll file: cannot read at 0x2C8. The properties of the project have been configured by adding library directory and files (Attached Figs. 1,2)

Thank you

* set LIB=%LIB%;C:\Program Files\MATLAB\R2012a\extern\lib\win64\microsoft and set PATH=%PATH%;C:\Program Files\MATLAB\R2012a\extern\lib\win64\microsoft

0 Kudos
1 Solution
IanH
Honored Contributor II
1,283 Views

You are specifying the path to the 64 bit libraries ("C:\...MATLAB\R2014b\extern\lib\win64\...") for a 32 bit build (the platform in VS is Win32).

Are you trying to build for 32 bit or 64 bit?

View solution in original post

0 Kudos
9 Replies
IanH
Honored Contributor II
1,283 Views

Remove the .DLL files from the additional dependencies property.

On Windows you link against an import library for a DLL (.lib extension), not directly against the DLL.

0 Kudos
Kami_M_
Beginner
1,283 Views

Thank you Ian for the response.

I removed .dll files from additional dependencies and got a set of errors (Fig. 3 in attachment). Just to make it more clear, my main program is Seis2SHalf and Matdata which is mentioned in errors is a module that uses Matlab libraries.

0 Kudos
IanH
Honored Contributor II
1,283 Views

Those symbols are in libmat.lib and libmx.lib.  Did you leave the .lib files in the additional dependencies line?

0 Kudos
Kami_M_
Beginner
1,283 Views

I also removed libmat.lib and libmx.lib from the additional dependencies in Linker/Input and I got the same errors (Fig. 3). Now, the only change in project properties is Matlab library path in Linker/General/"Additional library directories".

0 Kudos
IanH
Honored Contributor II
1,283 Views

Don't remove them - the .lib files need to be listed in the additional dependencies for the project that links MatData.obj.

If you are still having issues provide additional information about your project, for example by attaching the .vfproj.

0 Kudos
mecej4
Honored Contributor III
1,283 Views

Kami M: You have not absorbed a rather basic concept. You have to specify both which non-default libraries are to be linked with, and where those libraries are located. What you said #5, in effect, is "look for the additional libraries here <...>, but right now I don't need any". Simply add the import library names (not the DLL names) the "additional dependencies" list.

A similar situation exists w.rt. (i) include files and module files at compile time, and (ii) DLLs at run time. Include and module file requirements are embedded in the source code thorugh INCLUDE and USE statements. The information about DLL dependencies in the EXE you build is placed into the EXE by the linker, and the system loads those DLLs as needed by looking at the PATH environmental variable.

0 Kudos
Kami_M_
Beginner
1,283 Views

mecej4: Thank you for your comment.

Actually, I did #5 just to show Ian that by removing/leaving lib files I get the same error message (Fig. 3). I added lib files and got the same error message. I think there is a mistake somewhere else. Attached is a simple example of my project (exporting 1,2 and 4D arrays to mat file).

0 Kudos
IanH
Honored Contributor II
1,284 Views

You are specifying the path to the 64 bit libraries ("C:\...MATLAB\R2014b\extern\lib\win64\...") for a 32 bit build (the platform in VS is Win32).

Are you trying to build for 32 bit or 64 bit?

0 Kudos
Kami_M_
Beginner
1,283 Views

Thank you Ian, It works!

0 Kudos
Reply