- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you!
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks again,
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
C:Program FilesIntelCompilerFortran9.1IA32...
C++:
extern "C" { void __cdecl rdnist(); }
Fortran:
subroutine rdnist()
...
return
end
Error when compiling/linking the C++:
LNK2001: unresolved external symbol _rdnist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Error 1 error LNK2001: unresolved external symbol _for_stop_core
Error 2 error LNK2001: unresolved external symbol _for_stop_core
Error 3 error LNK2001: unresolved external symbol _for_stop_core
Error 4 error LNK2001: unresolved external symbol _for_read_seq_lis
Error 5 error LNK2001: unresolved external symbol _for_close
Error 6 error LNK2001: unresolved external symbol _for_rewind
Error 7 error LNK2001: unresolved external symbol _for_read_seq_fmt
Error 8 error LNK2001: unresolved external symbol _for_write_seq_fmt
Error 9 error LNK2001: unresolved external symbol _for_open
Error 10 error LNK2001: unresolved external symbol _for_f90_index
Error 11 error LNK2001: unresolved external symbol _for_cpstr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
1. Tools..Options..Projects..VC++ Directories..Library Files - add path to the Intel Fortran LIB folder
2. When creating the library project, Additional options, uncheck the box which says to disable default library search rules. If the project is already created, go to the Fortran>Libraries property page and set "Disable OBJCOMMENT Library Names in Object" to No
In addition, in VS2005 you have to add the Fortran .LIB file to the C main project (either as a "source file" or on the Linker "Additional Dependencies" option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I enabled the verbose setting on the c++ compiler. The output is below (sorry about the dump). I don't see anything obvious, but then, nothing about this project has been obvious to me
1>------ Rebuild All started: Project: NistWrapper, Configuration: Release Win32 ------
1>Deleting intermediate and output files for project 'NistWrapper', configuration 'Release|Win32'
1>Compiling...
1>NistWrapper.cpp
1>Linking...
1>Starting pass 1
1>Processed /DEFAULTLIB:uuid.lib
1>Processed /DEFAULTLIB:mcaduser.lib
1>Processed /DEFAULTLIB:RDNIST.lib
1>Processed /DEFAULTLIB:MSVCRT
1>Processed /DEFAULTLIB:OLDNAMES
1>Searching libraries
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibufferoverflowU.lib:
1> Found @__security_check_cookie@4
1> Referenced in NistWrapper.obj
1> Loaded bufferoverflowU.lib(secchk.obj)
1> Found ___report_gsfailure
1> Referenced in bufferoverflowU.lib(secchk.obj)
1> Loaded bufferoverflowU.lib(gs_report.obj)
1> Found ___security_cookie
1> Referenced in bufferoverflowU.lib(secchk.obj)
1> Referenced in bufferoverflowU.lib(gs_report.obj)
1> Loaded bufferoverflowU.lib(gs_support.obj)
1> Searching C:Documents and SettingssepolakMy DocumentsVisual Studio 2005ProjectsRDNISTRDNISTReleaseRDNIST.lib:
1> Found _RDNIST
1> Referenced in NistWrapper.obj
1> Loaded RDNIST.lib(rdnist.obj)
1> Found _FDATA
1> Referenced in RDNIST.lib(rdnist.obj)
1> Loaded RDNIST.lib(nist_cof_quiet_lump.obj)
1> Found _RDPROPS
1> Referenced in RDNIST.lib(rdnist.obj)
1> Loaded RDNIST.lib(rdprops.obj)
1> Found _PUSHRDPROPS
1> Referenced in RDNIST.lib(rdprops.obj)
1> Loaded RDNIST.lib(pushpoprdprops.obj)
1> Searching C:Program FilesMathsoftMathcad 13userefimicrosftlibMCADUSER.LIB:
1> Found _CreateUserErrorMessageTable
1> Referenced in NistWrapper.obj
1> Loaded MCADUSER.LIB(userdll.def)
1> Found _MathcadArrayAllocate
1> Referenced in NistWrapper.obj
1> Loaded MCADUSER.LIB(userdll.def)
1>&nbs p; Found _CreateUserFunction
1> Referenced in NistWrapper.obj
1> Loaded MCADUSER.LIB(userdll.def)
1> Found _MathcadArrayFree
1> Referenced in NistWrapper.obj
1> Loaded MCADUSER.LIB(userdll.def)
1> Found _isUserInterrupted
1> Referenced in NistWrapper.obj
1> Loaded MCADUSER.LIB(userdll.def)
1> Found __imp__CreateUserErrorMessageTable
1> Referenced in MCADUSER.LIB(userdll.def)
1> Loaded MCADUSER.LIB(userdll.def)
1> Found __imp__MathcadArrayAllocate
1> Referenced in MCADUSER.LIB(userdll.def)
1> Loaded MCADUSER.LIB(userdll.def)
1> Found __imp__CreateUserFunction
1> Referenced in MCADUSER.LIB(userdll.def)
1> Loaded MCADUSER.LIB(userdll.def)
1> Found __imp__MathcadArrayFree
1> Referenced in MCADUSER.LIB(userdll.def)
1> Loaded MCADUSER.LIB(userdll.def)
1> Found __imp__isUserInterrupted
1> Referenced in MCADUSER.LIB(userdll.def)
1> Loaded MCADUSER.LIB(userdll.def)
1> Found mcaduser_IMPORT_DESCRIPTOR
1> Referenced in MCADUSER.LIB(userdll.def)
1> Referenced in MCADUSER.LIB(userdll.def)
1> Referenced in MCADUSER.LIB(userdll.def)
1> Referenced in MCADUSER.LIB(userdll.def)
1> Referenced in MCADUSER.LIB(userdll.def)
1> Loaded MCADUSER.LIB(userdll.def)
1> Found NULL_IMPORT_DESCRIPTOR
1> Referenced in MCADUSER.LIB(userdll.def)
1> Loaded MCADUSER.LIB(userdll.def)
1> Found mcaduser__imp__NULL
1> Referenced in MCADUSER.LIB(userdll.def)
1> Loaded MCADUSER.LIB(userdll.def)
1> Searching C:Program FilesMicrosoft Visual Studio 8VClibkernel32.lib:
1> Found __imp__TerminateProcess@8
1> Referenced in bufferoverflowU.lib(gs_report.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __imp__GetCurrentProcess@0
1> Referenced in bufferoverflowU. lib(gs_report.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __imp__UnhandledExceptionFilter@4
1> Referenced in bufferoverflowU.lib(gs_report.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __imp__SetUnhandledExceptionFilter@4
1> Referenced in bufferoverflowU.lib(gs_report.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __imp__QueryPerformanceCounter@4
1> Referenced in bufferoverflowU.lib(gs_support.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __imp__GetTickCount@0
1> Referenced in bufferoverflowU.lib(gs_support.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __imp__GetCurrentThreadId@0
1> Referenced in bufferoverflowU.lib(gs_support.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __imp__GetCurrentProcessId@0
1> Referenced in bufferoverflowU.lib(gs_support.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __imp__GetSystemTimeAsFileTime@4
1> Referenced in bufferoverflowU.lib(gs_support.obj)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __IMPORT_DESCRIPTOR_KERNEL32
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found __NULL_IMPORT_DESCRIPTOR
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Found KERNEL32_NULL_THUNK_DATA
1> Referenced in kernel32.lib(KERNEL32.dll)
1> Loaded kernel32.lib(KERNEL32.dll)
1> Searching C:Program FilesMicrosoft Visual Studio 8VC PlatformSDKlibuser32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibgdi32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibwinspool.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibcomdlg32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibadvapi32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibshell32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibole32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKliboleaut32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VClibuuid.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibodbc32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibodbccp32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VClibMSVCRT.lib:
1> Found __fltused
1> Referenced in RDNIST.lib(rdnist.obj)
1> Referenced in RDNIST.lib(nist_cof_quiet_lump.obj)
1> Referenced in RDNIST.lib(rdprops.obj)
1> Referenced in RDNIST.lib(pushpoprdprops.obj)
1> Loaded MSVCRT.lib(dllsupp.obj)
1> Found _pow
1> Referenced in RDNIST.lib(nist_cof_quiet_lump.obj)
1> Loaded MSVCRT.lib(MSVCR80.dll)
1> Found _memmove
1> Referenced in RDNIST.lib(nist_cof_quiet_lump.obj)
1> Loaded MSVCRT.lib(MSVCR80.dll)
1> Found _exp
1> Referenced in RDNIST.lib(nist_cof_quiet_lump.obj)
1> Loaded MSVCRT.lib(MSVCR80.dll)
1> Found _log
1> Referenced in RDNIST.lib(nist_cof_quiet_lump.obj)
1> Loaded MSVCRT.lib(MSVCR80.dll)
1> Found __IMPORT_DESCRIPTOR_MSVCR80
1> Referenced in MSVCRT.lib(MSVCR80.dll)
1> Referenced in MSVCRT.lib(MSVCR80.dll)
1> Referenced in MSVCRT.lib(MSVCR80.dll)
1> Referenced in MSVCRT.lib(MSVCR80.dll)
1> Loaded MSVCRT.lib(MSVCR80.dll)
1> Found MSVCR80_NULL_THUNK_DATA
1> Referenced in MSVCRT.lib(MSVCR80.dll)
1> Loaded MSVCRT.lib(MSVCR80.dll)
1> Searching C:Program FilesMicrosoft Visua l Studio 8VClibOLDNAMES.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibufferoverflowU.lib:
1> Searching C:Documents and SettingssepolakMy DocumentsVisual Studio 2005ProjectsRDNISTRDNISTReleaseRDNIST.lib:
1> Searching C:Program FilesMathsoftMathcad 13userefimicrosftlibMCADUSER.LIB:
1> Searching C:Program FilesMicrosoft Visual Studio 8VClibkernel32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibuser32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibgdi32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibwinspool.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibcomdlg32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibadvapi32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibshell32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibole32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKliboleaut32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VClibuuid.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibodbc32.lib:
1> Searching C:Program FilesMicrosoft Visual Studio 8VCPlatformSDKlibodbccp32.lib:
1>Finished searching libraries
1>Finished pass 1
1>RDNIST.lib(rdnist.obj) : error LNK2001: unresolved external symbol _for_stop_core
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_stop_core
1>RDNIST.lib(rdprops.obj) : error LNK2001: unresolved external symbol _for_stop_core
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_read_seq_lis
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_close
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_rewind
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_read_seq_fmt
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_write_seq_fmt
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_open
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_f90_index
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_cpstr
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _for_cpystr
1>RDNIST.lib(nist_cof_quiet_lump.obj) : error LNK2001: unresolved external symbol _cbrt
1>RDNIST.lib(rdprops.obj) : error LNK2001: unresolved external symbol _for_write_seq_lis
1>RDNIST.lib(pushpoprdprops.obj) : error LNK2001: unresolved external symbol _for_write_seq_lis
1>RDNIST.lib(rdprops.obj) : error LNK2001: unresolved external symbol _for_write_seq_lis_xmit
1>RDNIST.lib(pushpoprdprops.obj) : error LNK2001: unresolved external symbol _for_write_seq_lis_xmit
1>C:Docu ments and SettingssepolakMy DocumentsVisual Studio 2005ProjectsNistWrapperReleaseNistWrapper.dll : fatal error LNK1120: 13 unresolved externals
1>Build log was saved at "file://c:Documents and SettingssepolakMy DocumentsVisual Studio 2005ProjectsNistWrapperNistWrapperReleaseBuildLog.htm"
1>NistWrapper - 18 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
-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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
dumpbin /directives whatever.obj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
At some point, I set the "Disable Default Library Search Rules" setting in the Fortran project to "Yes." After setting that back to "No," the nine C++ linking errors below went away. Now, I'm left with just this error:
RDNIST.lib(libifcoremain.obj) : error LNK2001: unresolved external symbol _MAIN__
Previous Post:
Ok, I tried opening the Fortran-compiled .obj files, but they aren't plain-text and I didn't see anything like that "-defaultlib:..." text in Steve's post. I even converted the file to HEX, but thta didn't help.
I also tried Jugoslav's suggestion, but using "dumpbin /directives foo.obj" (or "foo.lib") only gives me a summary of the file, and no information about library dependencies.
However, I did add the following default libs from Steve's post in the "Additional Dependencies" setting of the Fortran project:
ibifcoremt.lib libmmt.lib libirc.lib libifport.lib ifconsol.lib
After re-building the Fortran solution, I now get the following errors when trying to build/link the C++ solution:
Error 1 error LNK2001: unresolved external symbol __iob RDNIST.lib
Error 2 error LNK2001: unresolved external symbol __iob RDNIST.lib
Error 3 error LNK2001: unresolved external symbol __iob RDNIST.lib
Error 4 error LNK2001: unresolved external symbol ___mb_cur_max RDNIST.lib
Error 5 error LNK2001: unresolved external symbol ___mb_cur_max RDNIST.lib
Error 6 error LNK2001: unresolved external symbol __pctype RDNIST.lib
Error 7 error LNK2001: unresolved external symbol __pctype RDNIST.lib
Error 8 error LNK2001: unresolved external symbol ___argc RDNIST.lib
Error 9 error LNK2001: unresolved external symbol ___argv RDNIST.lib
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Might I suggest the following?
In the C-code
extern "C" { void __cdecl RDNIST(double *bar); }
double bar = 3.14;
returnValues[0] = bar;
RDNIST(bar);
returnValues[1] = bar;
and in the Fortran code:
SUBROUTINE RDNIST(FOO)
!
!DEC$ ATTRIBUTES C, REFERENCE, ALIAS : '_RDNIST' :: RDNIST
!DEC$ ATTRIBUTES REFERENCE :: FOO
REAL*8 FOO
FOO = FOO * 2
RETURN
END SUBROUTINE RDNIST
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ibifcoremt.lib libmmt.lib libirc.lib libifport.lib ifconsol.lib
Here is another piece of info that I just discovered... The Fortran code I have been working with (the real code, not the tests/examples I've posted) is apparently written in F66. Somebody else wrote this code a long time ago (like I said, I pretty clueless when it comes to Fortran). The file extensions of the Fortran source files I'm working with are *.f
The tests/examples I've created have been based on F90 code (*.f90 extension). These test/examples build and link into my C++ wrapper just fine, no errors. The F66 code, however, gives me unresolved external errors from the Fortran lib when I try to link the C++ project. Does that make sense? Is the Fortran compiler trying to include different libraries for the F66 code and the F90 code? Maybe that's inconsequential and far-fetched, but hopefully it helps shed some light on this problem of mine.
As usual, thanks for all your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
This Fortran lib I'm building is wrapped in a C++ dll.... The C++ dll provides all the user interface through OLE. With this in mind, do I even need any of the libs above? Are those all related to making the Fortran code into an application? Is there a way to exclude them from my Fortran project without having to modify this legacy Fortran code I'm trying to use?
Thanks!
Scott
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Make sure that there's no Fortran main program in your Fortran code you're building into the DLL.

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