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

c++ calling dll fortran subroutine including system command

ppxiao
Beginner
585 Views
I am trying to call fortran dll from c++. It works well for fortran subroutine without system command ("xxx.exe"). Currently the subroutine involves system command.


!ms$ if .not. defined(LINKDIRECT)
!ms$ attributes dllexport ::SUBFAN
!ms$ endif

...
call system("xxx.exe")

...

After building xx.dll and link with c++ project by adding xx.lib in linker input, it does not work. I have put xx.lib, xx.dll, xxx.exe in the working directory.

"unresolved external symbol _SUBFAN@60 referenced in function _main"

Will dll work in c++ if I have system (call system("xxx.exe")) inside the fortran subroutine?

Thank you



0 Kudos
4 Replies
TimP
Honored Contributor III
585 Views
I'm not certain of the answer, as there may be conflicts between Fortran system() and C system(). But, in order to give it a chance:
First, you should put USE IFPORT in your Fortran, and make your system call consistent with ifort implementation, as system isn't a Fortran standard until F2008, where it has a new name execute_command_line().
Then, assuming you use c++ to link your application, as you probably wish to do for a C++ main program, you will need also to link against specific Fortran libraries such as libifport and libifcore. Unless possibly you meet requirements to link the Fortran static libraries in the .dll.
0 Kudos
ppxiao
Beginner
585 Views
Thank you for your comments. I made some print out on the screen when using c++ calling dll. It is said

xxx.exe is not recognized as an internal or external command, operable program or batch file during execution
0 Kudos
ppxiao
Beginner
585 Views
Thank you very much for your comments.

I made some printout when executing c++ with fortran dll. It is said

xxx.exe is not recognized as an internal or external command, operable program or batch file
0 Kudos
ppxiao
Beginner
585 Views
Thanks. It works now. xxx.exe was confused about the path for the executable file.
0 Kudos
Reply