Fortran Coder

查看: 5577|回复: 4
打印 上一主题 下一主题

[混编] 请教:64位Intel fortran 调用64位Matlab出问题

[复制链接]

4

帖子

1

主题

0

精华

新人

F 币
26 元
贡献
13 点
跳转到指定楼层
楼主
发表于 2018-10-21 01:23:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 harptraveler 于 2018-10-22 02:18 编辑

各位大神,本人被从fortran调用matlab问题困扰了两个礼拜,特来求助,请大家不吝赐教!感激不尽!
我的操作环境

系统:64win10;Matlab版本:2018a;Fortran编译器:Intel parallel studio XE 2017fortran + Microsoft visual studio 2017;编译平台:Debug x64

问题描述:

试图用VS调用Matlab,无论VS中的程序是什么(即便是一个空程序),总会对第一行报错,output如下:

1>------ Build started: Project: Console2, Configuration: Debug x64 ------
1>Compiling with Intel(R) Visual Fortran Compiler 17.0.7.272 [Intel(R) 64]...
1>Source1.f90
1>C:\Users\Rui\FORTRAN\Console2\Console2/Source1.f90(1): error #5078: Unrecognized token '?' skipped
1>C:\Users\Rui\FORTRAN\Console2\Console2/Source1.f90(1): error #5078: Unrecognized token '?' skipped
1>C:\Users\Rui\FORTRAN\Console2\Console2/Source1.f90(1): error #5078: Unrecognized token '?' skipped
1>compilation aborted for C:\Users\Rui\FORTRAN\Console2\Console2\Source1.f90 (code 1)
1>
1>Build log written to  "file://C:\Users\Rui\FORTRAN\Console2\Console2\x64\Debug\BuildLog.htm"
1>Console2 - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



问题似乎出在Process source file上。当这一项为默认选项No的时候,没有上述问题,当然程序也无法编译。当把这一项改为Yes(/fpp)后,便会出现上述错误。
其他信息:
1.Matlab中用mex命令可以识别Intel Fortran

2.已在win10的环境变量中添加matlab路径

3.已将操作平台改为x64

4.已在项目-属性-Fortran-General里的AdditionalInclude Directories添加include

5. 已在项目-属性-Linker-General里的Additionallibrary directories里添加lib/win64/Microsoft

6. 已在项目-属性-linker-Input里的AdditionalDependencies里添加libmx.lib libmat.lib libeng.lib
谢谢大家!




分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

1961

帖子

12

主题

5

精华

论坛跑堂

臭石头雪球

F 币
1350 元
贡献
570 点

美女勋章热心勋章星光勋章新人勋章贡献勋章管理勋章帅哥勋章爱心勋章规矩勋章元老勋章水王勋章

沙发
发表于 2018-10-21 10:42:42 | 只看该作者
检查 Source1.f90 文件的编码,是否是 ANSI ,或者是 UTF-8 之类的。
改成 ANSI 之后再试试

4

帖子

1

主题

0

精华

新人

F 币
26 元
贡献
13 点
板凳
 楼主| 发表于 2018-10-22 02:15:29 | 只看该作者
本帖最后由 harptraveler 于 2018-10-22 02:18 编辑

非常感谢您!把编码改成UTF-8之后(找不到ANSI),就没有这个问题了。但用matlab官网提供的例子测试时,依然有错,请您指教。
output信息如下:
1>------ Build started: Project: Console2, Configuration: Debug x64 ------
1>Compiling with Intel(R) Visual Fortran Compiler 17.0.7.272 [Intel(R) 64]...
1>Source1.for
1>Linking...
1>Source1.obj : error LNK2019: unresolved external symbol MEXCALLMATLAB referenced in function MEXFUNCTION
1>libifcoremdd.lib(for_main.obj) : error LNK2019: unresolved external symbol MAIN__ referenced in function main
1>x64\Debug\Console2.exe : fatal error LNK1120: 2 unresolved externals
1>
1>Build log written to  "file://C:\Users\Rui\FORTRAN\Console2\Console2\x64\Debug\BuildLog.htm"
1>Console2 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

***********************************************************************************************************
所采用程序为matlab官网提供的测试程序passstr.f,用于把字符串从fortran传递到matlab:
#include "fintrf.h"
C=====================================================================
#if 0
C     
C     passstr.F
C     .F file needs to be preprocessed to generate .for equivalent
C     
#endif
C     
C     passstr.F is an example for illustrating passing a character
C     matrix from FORTRAN to MATLAB.
C
C     It passes a string array/character matrix into MATLAB as output
C     arguments rather than placing it directly into the workspace.
C      
C     Copyright 1984-2009 The MathWorks, Inc.
C     
C=====================================================================
C     Gateway routine
      subroutine mexFunction(nlhs, plhs, nrhs, prhs)

C     Declarations
      implicit none

C     mexFunction arguments:
      mwPointer plhs(*), prhs(*)
      integer nlhs, nrhs

C     Function declarations:
      mwPointer mxCreateString
      integer mexCallMATLAB

C     Pointers to input/output mxArrays:
      mwPointer input(1)

      integer status
      mwSize i, m, n
      character*75 thestring
      character*15 string(5)

C-----------------------------------------------------------------------
C     Create the string to be passed into MATLAB.
      string(1) = 'MATLAB         '
      string(2) = 'The Scientific '
      string(3) = 'Computing      '
      string(4) = 'Environment    '
      string(5) = '   by TMW, Inc.'
      
C     Concatenate the set of 5 strings into a long string.
      thestring = string(1)
      do 10 i=2,5
         thestring = thestring(:((i-1)*15)) // string(i)
10   continue
      
C     Create the string matrix to be passed into MATLAB.
      input(1) = mxCreateString(thestring)

C     Set the matrix size to be M=15 and N=5.
      m = 15
      call mxSetM(input(1), m)
      n = 5
      call mxSetN(input(1), n)
      
C     Transpose the resulting matrix in MATLAB because
C     Fortran stores arrays as column major.
      status = mexCallMATLAB(1, plhs, 1, input, 'transpose')

C     Cleanup the un-freed memory after calling mexCallMATLAB.
      call mxDestroyArray(input(1))

      return
      end

4

帖子

1

主题

0

精华

新人

F 币
26 元
贡献
13 点
地板
 楼主| 发表于 2018-10-22 02:16:26 | 只看该作者
fcode 发表于 2018-10-21 10:42
检查 Source1.f90 文件的编码,是否是 ANSI ,或者是 UTF-8 之类的。
改成 ANSI 之后再试试 ...

非常感谢您!把编码改成UTF-8之后(找不到ANSI),就没有这个问题了。但用matlab官网提供的例子测试时,依然有错,请您指教。
output信息如下:
1>------ Build started: Project: Console2, Configuration: Debug x64 ------
1>Compiling with Intel(R) Visual Fortran Compiler 17.0.7.272 [Intel(R) 64]...
1>Source1.for
1>Linking...
1>Source1.obj : error LNK2019: unresolved external symbol MEXCALLMATLAB referenced in function MEXFUNCTION
1>libifcoremdd.lib(for_main.obj) : error LNK2019: unresolved external symbol MAIN__ referenced in function main
1>x64\Debug\Console2.exe : fatal error LNK1120: 2 unresolved externals
1>
1>Build log written to  "file://C:\Users\Rui\FORTRAN\Console2\Console2\x64\Debug\BuildLog.htm"
1>Console2 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

***********************************************************************************************************
所采用程序为matlab官网提供的测试程序passstr.f,用于把字符串从fortran传递到matlab:
#include "fintrf.h"
C=====================================================================
#if 0
C     
C     passstr.F
C     .F file needs to be preprocessed to generate .for equivalent
C     
#endif
C     
C     passstr.F is an example for illustrating passing a character
C     matrix from FORTRAN to MATLAB.
C
C     It passes a string array/character matrix into MATLAB as output
C     arguments rather than placing it directly into the workspace.
C      
C     Copyright 1984-2009 The MathWorks, Inc.
C     
C=====================================================================
C     Gateway routine
      subroutine mexFunction(nlhs, plhs, nrhs, prhs)

C     Declarations
      implicit none

C     mexFunction arguments:
      mwPointer plhs(*), prhs(*)
      integer nlhs, nrhs

C     Function declarations:
      mwPointer mxCreateString
      integer mexCallMATLAB

C     Pointers to input/output mxArrays:
      mwPointer input(1)

      integer status
      mwSize i, m, n
      character*75 thestring
      character*15 string(5)

C-----------------------------------------------------------------------
C     Create the string to be passed into MATLAB.
      string(1) = 'MATLAB         '
      string(2) = 'The Scientific '
      string(3) = 'Computing      '
      string(4) = 'Environment    '
      string(5) = '   by TMW, Inc.'
      
C     Concatenate the set of 5 strings into a long string.
      thestring = string(1)
      do 10 i=2,5
         thestring = thestring(:((i-1)*15)) // string(i)
10   continue
      
C     Create the string matrix to be passed into MATLAB.
      input(1) = mxCreateString(thestring)

C     Set the matrix size to be M=15 and N=5.
      m = 15
      call mxSetM(input(1), m)
      n = 5
      call mxSetN(input(1), n)
      
C     Transpose the resulting matrix in MATLAB because
C     Fortran stores arrays as column major.
      status = mexCallMATLAB(1, plhs, 1, input, 'transpose')

C     Cleanup the un-freed memory after calling mexCallMATLAB.
      call mxDestroyArray(input(1))

      return
      end

4

帖子

1

主题

0

精华

新人

F 币
26 元
贡献
13 点
5#
 楼主| 发表于 2018-10-22 19:58:31 | 只看该作者
用了这个例子,测试成功!谢谢!https://ww2.mathworks.cn/help/matlab/matlab_external/call-matlab-functions-from-fortran-applications.html
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-4-25 12:22

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表