MODULE ARRAY_STORAGE
REAL*8, ALLOCATABLE :: ARRAY(:)
END MODULE ARRAY_STORAGE
function ffunc(n1,n2)
USE ARRAY_STORAGE
integer ffunc
character*256 filename
integer n1,n2,iret
integer*4 stat
ALLOCATE (ARRAY(10),stat=stat)
if (stat/=0) then
write (*,*) 'problem allocating array : stat=',stat
else
write (*,*) 'array allocated as size', size(array)*8./(2.**20),
+' mb at LOC',loc(array)
end if
ffunc = n1+n2
return
end
Define "not working".
Also, this won't link as written, every occurrence of ffunc needs to be ffunc_, in the C++ file.
With that change, it compiles and runs for me:
1 2 3
$ ./test
Calling from C++ to Fortran, arguments: 1, 2
array allocated as size 0.7629394531E-04 mb at LOC 805435768
I'm using Visual Studio Environment. I don't need ffunc_.
I can confirm because if I comment USE ARRAY_STORAGE and comment the module portionas well in .F file- all works and the function is called.
The problem happens when the USE ARRAY_STORAGE is put in
One of the error is: Error 25 fatal error LNK1169: one or more multiply defined symbols found D:\ajay_2012\FFES\fortran_to_cpp\cpptest\Debug\cpptest.exe cpptest
And other erros are:
Error 1 error LNK2005: __CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 2 error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 3 error LNK2005: __exit already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 4 error LNK2005: __cexit already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 5 error LNK2005: __amsg_exit already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 6 error LNK2005: __initterm_e already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 7 error LNK2005: __crt_debugger_hook already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 8 error LNK2005: __invoke_watson already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 9 error LNK2005: __configthreadlocale already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 10 error LNK2005: __encode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 11 error LNK2005: __decode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 12 error LNK2005: __XcptFilter already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 13 error LNK2005: ___xi_a already defined in MSVCRTD.lib(cinitexe.obj) LIBCMTD.lib cpptest
Error 14 error LNK2005: ___xi_z already defined in MSVCRTD.lib(cinitexe.obj) LIBCMTD.lib cpptest
Error 15 error LNK2005: ___xc_a already defined in MSVCRTD.lib(cinitexe.obj) LIBCMTD.lib cpptest
Error 16 error LNK2005: ___xc_z already defined in MSVCRTD.lib(cinitexe.obj) LIBCMTD.lib cpptest
Error 17 error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 18 error LNK2005: __lock already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 19 error LNK2005: __unlock already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 20 error LNK2005: _mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj) LIBCMTD.lib cpptest
Error 21 error LNK2005: ___set_app_type already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Error 22 error LNK2005: __CrtDbgReportW already defined in MSVCRTD.lib(MSVCR90D.dll) LIBCMTD.lib cpptest
Warning 23 warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library cpptest cpptest
Warning 24 warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library cpptest cpptest