- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, I went back to basics:
IVF code:
program fortran_c_test
implicit none
interface
subroutine c_code_test(index,foo)
!DEC$ ATTRIBUTES C, ALIAS:'_c_code_test' :: c_code_test
integer index
real(8) foo
end subroutine c_code_test
end interface
integer index
real(8) foo
index = 3
call c_code_test(index,foo)
write(*,*) foo
stop
end
MVS C++(C) code
#include
void c_code_test(index,foo)
int index;
double *foo;
{
*foo = 3.21 * index;
}
This is compiled and put into: C:mhoversfortran_c_testDebugc_code_dir.lib
In Project->Linker->Input->Additional Dependencies I have c_code_dir.lib
In Project->Linker->General->Additional Library Directories I have
C:mhoversfortran_c_testDebug
In Tools->Options->Intel Fortran->General->Libraries I have
C:mhoversfortran_c_testDebug
When I build fortran_c_test I get:
error LINK2019: unresolved external symbol _c_code_test referenced in function _MAIN__
Have I screwed up the INTERFACE or what?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If your "C++(C)" code has a .cpp file type, you need to add:
extern "C"
before the "void" so as to suppress C++ name mangling.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry about the new threads, I will use "reply" from now on.
The C code is c_code_test.c and I have set:
Project->Properties->Configuration Properties->C/C++->Advanced/Compile as C Code (/TC).
However, my f90 application still give an unresolved external for the _c_code_test.
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try replacing
void c_code_test
with
void __stdcall c_code_test
(Note thedouble underscore)
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With 'ATTRIBUTES C' set in the Fortran, perhaps ' __cdecl' in the C might be needed.
Also, in the Fortran,I think 'VALUE' and 'REFERENCE' attributes should be specified for the 2 arguments.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes of course. I was looking at our ownFortran->C code and jumped in without looking carefully at the OP code. :-(
In the Fortran help look for "Attibutes Properties and Calling Conventions"
Les
- 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
------ Build started: Project: fortran_c_test, Configuration: Debug|Win32 ------
The build log is below, I looks like it is looking in c_code_dir.lib??
Linking...
Link /OUT:"Debug/fortran_c_test.exe
" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:mhoversfortran_c_testc_code_dirDebug" /MANIFEST /MANIFESTFILE:"C:mhoversfortran_c_testdebugfortran_c_test.exe.intermediate.manifest" /DEBUG /PDB:"Debug/fortran_c_test.pdb" /MAP:"fortran_c_test_map" /SUBSYSTEM:CONSOLE c_code_dir.lib "Debug/fortran_c_test.obj"Link: executing 'link'
fortran_c_test.obj : error LNK2019: unresolved external symbol _C_CODE_TEST referenced in function _MAIN__
Debug/fortran_c_test.exe : fatal error LNK1120: 1 unresolved externals
fortran_c_test build failed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Maybe the problem is in the building of the C code library??
Under Project Defaults I have:
Configuration type: Static Library (.lib)
Use of MFCUse Standared Windows Libraries
Use of ATLNot Using ATL
Minimize CRT Use in ATLNO
Common Language Runtime supportNo Common Language runtime support
Are there any things I should check in the C library build??
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are you using VS2005? If so, have you installed VS2005 Service Pack 1? If not, uninstall the Intel Fortran integrations, install VS05 SP1 and reinstall the integrations. This will probably fix the problem.
Next, is the static library project a "dependent" of the executable project? Right click on the executable and select Dependencies. Make sure the box for the library is checked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will have to install the service pac. I only mess with the fortran integration with MVS every couple of years when I get new systems and it never goes smoothly. Can you tell me the order. Should I 1) instlll MVS, 2) install the survice pac, 3) install IVF ? I can't remember if I need IVF installed before MVS for it to do the integration or not?
The above assumes that I uninstall everything and start from scratch, which is usually the only way I can get any of the MVS IVF inegration to work, but I would try to "uninstall the IVF integration, and re-install it if you can direct me to how to do that.
thanks very much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2. Download and install VS2005 SP1.
3.. Locate the file C:Program FilesIntelDownloadIntelFortranCompiler10installsw_ide_p_10.0.xxx.exe (where xxx is the latest number on your system - the _p_ may be _c_ instead) and run it.
This should take care of it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, got the service pac installed and the IVF fortran interface re-installed. Still no joy.
For completeness here is the code and build.log
program fortran_c_test implicit none interface subroutine c_code_test(index,foo) !DEC$ ATTRIBUTES C, ALIAS:'_c_code_test' :: c_code_test !DEC$ ATTRIBUTES VALUE :: index !DEC$ ATTRIBUTES REFERENCE :: foo integer index real(8) foo end subroutine c_code_test end interface integer index real(8) fooindex = 3
call c_code_test(index,foo) write(*,*) foo stopend
C- Code:
#include
void
c_code_test(index,foo)int
index;double
*foo;{
*foo = 3.21 * index;
}
Build Log:
------ Build started: Project: fortran_c_test, Configuration: Debug|Win32 ------
Compiling with Intel Fortran Compiler 10.0.025 [IA-32]...
ifort /nologo /Zi /Od /module:"Debug/
" /object:"Debug/" /traceback /check:bounds /libs:static /threads /dbglibs /c /Qvc8 /Qlocation,link,"C:Program FilesMicrosoft Visual Studio 8VCin" "C:mhoversfortran_c_testfortran_c_test.F90"Linking...
Link /OUT:"Debug/fortran_c_test.exe
" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:mhoversfortran_c_testc_code_dirDebug" /MANIFEST /MANIFESTFI LE:"C:mhoversfortran_c_testdebugfortran_c_test.exe.intermediate.manifest" /DEBUG /PDB:"Debug/fortran_c_test.pdb" /MAP:"fortran_c_test_map" /SUBSYSTEM:CONSOLE c_code_dir.lib "Debug/fortran_c_test.obj"Link: executing 'link'
fortran_c_test.obj : error LNK2019: unresolved external symbol c_code_test referenced in function _MAIN__
Debug/fortran_c_test.exe : fatal error LNK1120: 1 unresolved externals
fortran_c_test - 2 error(s), 0 warning(s)
Is this a naming convention problem now?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have attached a ZIP of a working build. Compare it to yours. In particular, make sure that the Fortran project is the "start up project" (shown in bold) and that the C library project is a dependent of the Fortran project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your project works fine. I notice that you have the C and Fortran all in one. I had a seperate C project to build a static library and a seperate Fortran project that tried to link to it.
Where can I find instructions on how to have multiple directiories and source code types in one project as you have done?
Thanks very much for all your help, I never would have figured this out (may still not when I have to go add the real stuff) without your help.
cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To do this from scratch, use Add, New Project. Either way, you'll then want to right click on the executable project, select Dependencies, and check the box for the library project. Also make sure that the executable project is the "startup project" (shown in bold). If not, right click on it and select Set As Startup Project.
How did you specify that the C library should be linked in?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In MVS before the upgrade to SP1 there was a button under Project types -> Visual C++ to build static libraries (*.lib). That is gone now. How do I build a static library project now?
Thanks,
- 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 am trying to reproduce the example you sent which works on my system. I have created the 2 projects, built the static lib and set the dependencies in the fortran project. When I try to build I get the following errors.
I have tried to compare all of the properties between your projects and mind and can find no differences (although I know they must exist). Somehow my build is having trouble with MSVCRTD.lib but I cant figure out why?
Linking...
Link /OUT:"Debugfortran_c_test2.exe
" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:"C:mhoversfortran_c_test2debugfortran_c_test2.exe.intermediate.manifest" /DEBUG /PDB:"C:mhoversfortran_c_test2debugfortran_c_test2.pdb" /SUBSYSTEM:CONSOLE "Debugfortran_c_test.obj" "c:mhoversfortran_c_test2debugc_code.lib"Link: executing 'link'
c_code.lib(c_code_dir.obj) : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const
&)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info
& __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
Debugfortran_c_test2.exe : fatal error LNK1169: one or more multiply defined symbols found
- 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
OK, now I can build my version of the test code. Now I am trying to get it real. I need to allocate memory in the fortran and pass it into the c code. I have:
program fortran_c_test
implicit none
interface
subroutine c_code_test(index,foo,val)
!DEC$ ATTRIBUTES C, ALIAS:'_c_code_test' :: c_code_test
!DEC$ ATTRIBUTES VALUE :: index
!DEC$ ATTRIBUTES REFERENCE :: foo
!DEC$ ATTRIBUTES REFERENCE :: val
integer index
real(8) foo
complex(8) val
end subroutine c_code_test
end interface
integer index, n, i
complex(8), dimension(:), allocatable :: val
n=5
allocate(val(n))
do i=1,n
val(i) = dcmplx(0.5, 1.2) * i;
end do
index = 3
call c_code_test(index,foo,val)
write(*,*) foo
stop
end
#include
typedef struct { double r, i; } doublecomplex;
void c_code_test(index,foo,val)
int index;
double *foo;
doublecomplex *val;
{
*foo = 3.21 * index;
}
As long as val is a single complex(8) all is well, but as soon as I allocate val I get:
C:mhoversfortran_c_test2fortran_c_test.f90(29) : Error: The shape matching rules of actual arguments and dummy arguments have been violated. [VAL]
compilation aborted for C:mhoversfortran_c_test2fortran_c_test.f90 (code 1)
The c_code_test routine matches the real c code I am trying to interface, so any changes to make this work need to be in the calling fortran code.
thanks,

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