Why can I link my Intel Fortran dll (sum_if.dll) to my Fortran (sum_test) but not my C++ one (sum_cpp.dll)? All are accepted as STDCAL DLLs by other software e.g. Excel VBA (in the attached .zip)
Fortran Linking to sum_if works with any of:
- Linker | Input | Additional Dependecies= sum_if.lib
- Adding.lib to project (e.g. sum_if.lib)
- Project Dependencies = sum_if
But for sum_cpp the dll is not found or accepted i.e.
sum_test.obj : error LNK2019: unresolved external symbol __imp_sum referenced in function _MAIN__
Dependency Walker shows function=sum on both. So hopefully it is not a "Decoration" issue?
I have attached the VS Community 2013 Solution, as I hope/ expect the answer is hidden there.
1. VS 2013 Solution= sumdll Projects: = Win32,
All sharing same ..\Output\Release and Debug directories. The excel “double check” lives in Debug. This helps simplify and clarify "finding" the DLL (I wanted to avoid full paths)
1.1 Sum_if.dll contains:
function sum(a,b) IMPLICIT NONE ! Expose subroutine ExcelDLL to users of this DLL !DEC$ATTRIBUTES STDCALL, DLLEXPORT, ALIAS: 'sum' :: sum !DEC$ATTRIBUTES Value :: a,b ! Variables integer*4 a,b,sum ! Body of ExcelDLL sum=a+b end function sum
1.2 Sum_cpp.dll
// Sum_cpp.cpp contains: int _stdcall sum(int x, int y){ return x+y; } // Sum_cpp.def contains: LIBRARY "sum_cpp"" EXPORTS sum @
1.3 Sum_test
Interface function sum(a,b) IMPLICIT NONE ! Expose subroutine ExcelDLL to users of this DLL !DEC$ ATTRIBUTES DLLIMPORT, ALIAS:'sum' :: sum !DEC$ATTRIBUTES Value :: a,b ! Variables INTEGER*4 a,b,sum end function sum End Interface INTEGER*4 :: a_i4b, b_i4b, c_i4b,d_i4b, I, j print *, 'add integers' a_i4b=7 b_i4b=43 c_i4b=sum(a_i4b,b_i4b) write(*,'(I10,A,I10,A,I10)') a_i4b," + ", b_i4b," = ",c_i4b end program vf_dll_test
2. Excel VBA Declares
' all work fine:' C++ Declare Function sumcpp Lib "sum_cpp.dll" Alias "sum" (ByVal i As Long, ByVal j As Long) As Long' Intel Fortran 10.1 Declare Function sumif Lib "sum_if.dll" Alias "sum" (ByVal a As Long, ByVal b As Long) As Long
Peter