- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First, a disclaimer: I know very little about Fortran and C++
I have some Fortran code that I have compiled into a multi-threaded static library. I want to call a subroutine in that Fortran code from a C++ "wrapper" application (DLL). I have been able to compile and link the Fortran and C++ code, however, when I pass arguments to the Fortran subroutine, they do not appear to be passed by reference. Here is some test code I am working with:
Fortran:
I have some Fortran code that I have compiled into a multi-threaded static library. I want to call a subroutine in that Fortran code from a C++ "wrapper" application (DLL). I have been able to compile and link the Fortran and C++ code, however, when I pass arguments to the Fortran subroutine, they do not appear to be passed by reference. Here is some test code I am working with:
Fortran:
SUBROUTINE RDNIST(FOO)
!DEC$ATTRIBUTES REFERENCE, ALIAS: "_RDNIST":: RDNIST
FOO = FOO * 2
return
END
C++:
extern "C" void __cdecl RDNIST(double *);
double bar = 3.14;
returnValues[0] = bar;
RDNIST(&bar);
returnValues[1] = bar;
Using the above code, the values of returnValues[0] and returnValues[1] are the same, both 3.14.
I have also tried using __stdcall instead of __cdecl, but the results are the same. Also, I tried compiling the Fortran lib with various calling conventions (C, REF... STDCALL, REF... etc). I have a feeling I'm missing some basic multi-language concept/rule. Any help will be greatly appreciated.
For reference, I am using MVS 2005 .NET, with IVF 9.1
Thanks!
Scott
Link Copied
- « Previous
-
- 1
- 2
- Next »
28 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Alright, I removed all those specific libs (mentioned in the post below) from the "additional dependencies" list. I even set "Ignore All Default Libs" to "Yes," but when I build the Fortran and run "dumpbin" on the resulting lib, the list of Linker Directives is the same as before:
Linker Directives
-----------------
-defaultlib:ifconsol
-defaultlib:libifcoremt
-defaultlib:libifport
-defaultlib:libmmt
-defaultlib:LIBCMT
-defaultlib:libirc
-defaultlib:OLDNAMES
-defaultlib:ifconsol
-defaultlib:libifcoremt
-defaultlib:libifport
-defaultlib:libmmt
-defaultlib:LIBCMT
-defaultlib:libirc
-defaultlib:OLDNAMES
Also, I verified that there is no "main" program in any of the Fortran files. The Fortran lib (with the current settings) builds without any errors. But when I try to link into the C++ DLL, I get this error:
Error 1 error LNK2001: unresolved external symbol _MAIN__ libifcoremt.lib
Linker Directives
-----------------
-defaultlib:ifconsol
-defaultlib:libifcoremt
-defaultlib:libifport
-defaultlib:libmmt
-defaultlib:LIBCMT
-defaultlib:libirc
-defaultlib:OLDNAMES
-defaultlib:ifconsol
-defaultlib:libifcoremt
-defaultlib:libifport
-defaultlib:libmmt
-defaultlib:LIBCMT
-defaultlib:libirc
-defaultlib:OLDNAMES
Also, I verified that there is no "main" program in any of the Fortran files. The Fortran lib (with the current settings) builds without any errors. But when I try to link into the C++ DLL, I get this error:
Error 1 error LNK2001: unresolved external symbol _MAIN__ libifcoremt.lib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is something else going on not evident from the data shown here. Please submit an issue to Intel Premier Support, attach a ZIP of your solution folder, and we'll take a look. Please ask that it be assigned to Steve Lionel.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem turned out to be:
1) Different runtime library specified for C and Fortran project - these must be consistent
2) libifcoremt.lib explicitly listed as an additional dependency in C project - remove
3) msvcrt.lib listed as "ignore" in C project - remove
1) Different runtime library specified for C and Fortran project - these must be consistent
2) libifcoremt.lib explicitly listed as an additional dependency in C project - remove
3) msvcrt.lib listed as "ignore" in C project - remove
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, indeed. I think item 1 was the big contributor to my problem. In my many attempts to debug this problem, I had tried building the c++ project with and without items 2 and 3, but it didn't seem to make a difference. However, the fact that my Fortran project was set as "Multithreaded" and the c++ project was set to "Multithreaded DLL," that was huge. Setting them both to "Multithreaded DLL" made everything happy.
Steve, you and this forum are an excellent resource and have helped me greatly. Thanks again.
Steve, you and this forum are an excellent resource and have helped me greatly. Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ahhh, just when I thought everything was working ![Sad smiley [:(]](/ISN/Community/en-US/emoticons/emotion-9.gif)
So, I am able to compile and link the fortran lib into the c++ dll, and the dll works perfectly on my computer (it's a dll that provides a "user function" within the MathCAD software). however, when I distribute the dll to a co-worker's computer, using the exact same version of MathCAD, it does not work. This other person's computer does not have Intel Visual Fortran installed. Forgive my ignorance, but do the Fortran run-time libraries need to be present in order to use this c++ based dll that links a Fortran lib? If so, is there any way to compile/link the Fortran lib so it doesn't require IVF to run?
Hopefully this is the last hurdle. Thanks!
![Sad smiley [:(]](/ISN/Community/en-US/emoticons/emotion-9.gif)
So, I am able to compile and link the fortran lib into the c++ dll, and the dll works perfectly on my computer (it's a dll that provides a "user function" within the MathCAD software). however, when I distribute the dll to a co-worker's computer, using the exact same version of MathCAD, it does not work. This other person's computer does not have Intel Visual Fortran installed. Forgive my ignorance, but do the Fortran run-time libraries need to be present in order to use this c++ based dll that links a Fortran lib? If so, is there any way to compile/link the Fortran lib so it doesn't require IVF to run?
Hopefully this is the last hurdle. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The user does not need to have IVF installed, but they would need certain IVF run-time DLLs also present. They might also need certain MSVC DLLs present if they don't have the same version of Visual Studio.
You can change the Runtime Library settings in BOTH projects to be "Multithreaded" (not Multithreaded DLL) and it should do what you want.
You can change the Runtime Library settings in BOTH projects to be "Multithreaded" (not Multithreaded DLL) and it should do what you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This sounds like a job for Dependency Walker, free software from www.dependencywalker.com . Run it past your .dll or .exe and it will show you what other
.dll's are required for it to run.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the link and the idications.

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
- « Previous
-
- 1
- 2
- Next »