- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am new to fortran, so I apologize in advance if my question is lame.Is there any guide related to how to mix C++ and Fortran using Intel Fortran compiler and visual studio? A C clone of quadpack crashed on some inputs while the fortran one returns a value, so I need to use the fortran version in my C app.
Any help on these is much appreciated, I have a tight academic deadline to meet and GSL just gave up on me. Many thanks,
Daniel
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Given that you are not experienced in Fortran, you may exchange one problem for a bigger one by doing what you described.
Show the Quadpack routine references in your C code, along with the declarations of the function arguments, and I can perhaps suggest how to link to Quadpack in a Fortran library or DLL.
Show the Quadpack routine references in your C code, along with the declarations of the function arguments, and I can perhaps suggest how to link to Quadpack in a Fortran library or DLL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, thanks for the answer. I have downloaded quadpack from
and developed a piece of fortran code to call qagi. The code is
[fortran]real function MomentWei(kappa, p, v)
COMMON/weibullCommon/ CKAPPA,CP
real CKAPPA
real CP
real kappa
real p
real v
real xi
real gammafact
real res
real error
integer evaluations
integer errorindication
real, external :: logpweibulIntegrand
CKAPPA = kappa
CP = p
if ( v .ne. 0 ) then
! v != 0
xi = gammafact( 1.0 + 1.0/kappa)
res = (1.0/xi) ** (v*p) * gammafact( 1.0 + v*p/kappa)
else
! v == 0
call qagi(logpweibulIntegrand, 0.0, 1, 1e-08, 1e-08, res, error, evaluations, errorindication )
if ( errorindication .lt. 0 ) stop 'MomentWei >>> Abnormal qagi termination'
end if
if ( isnan(res) ) stop 'MomentWei >>> Integral is a NaN'
MomentWei = res
end
[/fortran]
where "logpweibulIntegrand" is some function of the correct type. I tested the code, it works. Now I have a C app...
[cpp]
#includeand when I use MSVC 2010 and include a directory with intel fortran libraries to the linking process, all is OK. However, when I use Intel C Compiler from MSVC 2010, I getlinker errors, namely ...extern "C" { extern float MOMENTWEI(float * kappa, float * p, float * x); } int main(void) { float kappa = 1.0; float p = 2.0; float x = 0.5; float Res; Res = MOMENTWEI( & kappa, & p, & x); return 0; };[/cpp]
Link:
xilink: executing 'link'
LIBCMTD.lib(dbgheap.obj) : error LNK2005: __CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR100D.dll)
LIBCMTD.lib(invarg.obj) : error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR100D.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR100D.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: __exit already defined in MSVCRTD.lib(MSVCR100D.dll)
LIBCMTD.lib(crt0dat.obj) : error LNK2005: __cexit already defined in MSVCRTD.lib(MSVCR100D.dll)
......
The app runs OK, but speed is of essence in here, so I would like to have the possibility to compile with ICC. If it is straight forward, what Im doing wrong, please tell me.
Thank you again,
Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have the dread disease "Mixed C Library Syndrome". Fortunately, science has a cure. The C project and the Fortran project are asking for different types of run-time library. C defaults to DLL, where Fortran defaults to static. In your Fortran project, change property Fortran > Libraries > Use runtime library" to "Multithreaded Debug DLL" (for the Debug configuration) and "Multithreaded DLL" for Release.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you both!
Daniel

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page