主题:请教VC调用fortran的实现
zqb138
[专家分:160] 发布于 2011-11-23 23:02:00
我用VC建立了基于一个对话框界面的工程,同时也有一个fortran源程序。想实现在对话框界面中调用这个fortran程序。网上见到的要么是c++的控制台程序调用fortran的,要么就是VC调用fortran的DLL的。是否有把这个界面工程包含fortran程序直接进行编译的方法?
回复列表 (共18个回复)
沙发
cgl_lgs [专家分:21040] 发布于 2011-11-24 08:05:00
VC6与CVF可以直接混编,但CVF太老了。
IVF与C++源码如果想放在一个工程编译,那就必须使用ICC(Intel C++ Compiler)。
不过你可以把Fortran编译成lib放到vc工程里:)
板凳
zqb138 [专家分:160] 发布于 2011-11-24 09:14:00
我用的就是VC6和CVF,楼上所说的‘VC6与CVF可以直接混编’,可以详细介绍一下吗?我只想要用VC作一个可视化界面,通过可视化界面传递参数数据到fortran源程序中并计算后传回VC交互界面。同时我经常修改fortran源程序,不想每次都先把它编译成lib或DLL然后再在VC中调用,很麻烦。是否可以编译VC的时候能同时把这个fortran源程序一并编译就好了,直接快捷。
3 楼
zqb138 [专家分:160] 发布于 2011-11-24 10:25:00
工程名:cfd. 单对话框工程,包含三个编辑框和一个按钮,对应float变量名m_a,m_b,m_c。一个fortran文件forsubs.f90包含在工程source files中,内容为
SUBROUTINE Pythagoras(a,b,e)
REAL*4 a[VALUE]
REAL*4 b[VALUE]
REAL*4 e[REFERENCE]
e=SQRT(a*a+b*b)
END
另在cfdDlg.cpp中加入extern "C" {void _stdcall Pythagoras(float a,float b,float *c);}
并有
void CCfdDlg::Oncompute()
{
// TODO: Add your control notification handler code here
UpdateData();
Pythagoras(m_a,m_b,&m_c);
}
开始编译,错误很多如下:
Linking...
dfor.lib(matherr.obj) : error LNK2005: __matherr already defined in msvcrtd.lib(merr.obj)
libcd.lib(fpinit.obj) : error LNK2005: __ldused already defined in a previous module
libcd.lib(fpinit.obj) : error LNK2005: __fltused already defined in a previous module
libcd.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcd.lib(crt0dat.obj) : error LNK2005: __exit already defined in msvcrtd.lib(MSVCRTD.dll)
libcd.lib(ieee87.obj) : error LNK2005: __controlfp already defined in msvcrtd.lib(MSVCRTD.dll)
libcd.lib(winxfltr.obj) : error LNK2005: __XcptFilter already defined in msvcrtd.lib(MSVCRTD.dll)
libcd.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
libcd.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
libcd.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
libcd.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
msvcrtd.lib(MSVCRTD.dll) : error LNK2005: __setmbcp already defined in libcd.lib(mbctype.obj)
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "libcd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
cfdDlg.obj : error LNK2001: unresolved external symbol _Pythagoras@12
dfor.lib(DFORMAIN.OBJ) : error LNK2001: unresolved external symbol _MAIN__
Debug/cfd.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
cfd.exe - 15 error(s), 2 warning(s)
4 楼
cgl_lgs [专家分:21040] 发布于 2011-11-24 12:07:00
Fortran选项与C选项需要一致:)
你这里应该是Fortran选了静态库,而C用了动态库:)
5 楼
zqb138 [专家分:160] 发布于 2011-11-24 12:55:00
那应该如何设置呢?我对这个还真不知道,望赐教。
6 楼
cgl_lgs [专家分:21040] 发布于 2011-11-24 14:04:00
这个。。。一句两句说不清啊,而且这儿还贴不了图。。。
7 楼
cgl_lgs [专家分:21040] 发布于 2011-11-24 14:12:00
要不你把dsp文件的内容贴上来,我看看能不能给你改改吧。
8 楼
zqb138 [专家分:160] 发布于 2011-11-24 15:38:00
# Microsoft Developer Studio Project File - Name="cfd" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=cfd - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "cfd.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "cfd.mak" CFG="cfd - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "cfd - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "cfd - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
F90=df.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "cfd - Win32 Release"
# PROP BASE Use_MFC 6
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 6
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE F90 /compile_only /nologo /warn:nofileopt /winapp
# ADD F90 /compile_only /nologo /warn:nofileopt /winapp
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Yu"stdafx.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x804 /d "NDEBUG" /d "_AFXDLL"
# ADD RSC /l 0x804 /d "NDEBUG" /d "_AFXDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /subsystem:windows /machine:I386
# ADD LINK32 /nologo /subsystem:windows /machine:I386
!ELSEIF "$(CFG)" == "cfd - Win32 Debug"
# PROP BASE Use_MFC 6
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 6
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE F90 /check:bounds /compile_only /dbglibs /debug:full /nologo /traceback /warn:argument_checking /warn:nofileopt /winapp
# ADD F90 /check:bounds /compile_only /dbglibs /debug:full /nologo /traceback /warn:argument_checking /warn:nofileopt /winapp
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Yu"stdafx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x804 /d "_DEBUG" /d "_AFXDLL"
# ADD RSC /l 0x804 /d "_DEBUG" /d "_AFXDLL"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
# ADD LINK32 /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "cfd - Win32 Release"
# Name "cfd - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;f90;for;f;fpp"
# Begin Source File
SOURCE=.\cfd.cpp
# End Source File
# Begin Source File
SOURCE=.\cfd.rc
# End Source File
# Begin Source File
9 楼
cgl_lgs [专家分:21040] 发布于 2011-11-24 20:56:00
哥,不完整啊,难道回头我贴回来时也贴不完整的?
10 楼
zqb138 [专家分:160] 发布于 2011-11-24 21:04:00
是完整的啊,我把dsp文件中的内容全部拷贝进来了呀!
我来回复