- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I am trying to use structures/modules to pass data between vc++ and IVF. As a test, I basically cut-and-pasted the example from "using modules in mixed-language programming" in the users guide. To be more precise, I created a win32 console app and then created a fortran static lib as a subproject. I then created a file 'EXAMPLE.f90' and added the module definition
MODULE EXAMP etc.
I then created a second fortran file containing a subroutine using the module, and gave the module vars values. In my c++ project I then declared the module vars as globals, using the extern "C" dec
extern "C" int EXAMP_mp_I1, EXAMP_mp_I2;
This would compile and link fine, but if I then tried to use the vars in my c++ program, i.e.
std::cout << " EXAMP_mp_I1 = " << EXAMP_mp_I1 << std::endl;
I get link errors
mixedTest error LNK2001: unresolved external symbol _EXAMP_mp_I1
I am assuming this is some sort of name-mangling problem (for example, in the "fortran module names and attributes" part of the users guide, it seemed to suggest that there may be an underscore prefix added to the var?) I have been able to call fortran, etc. from c++ in the past (w/out modules) so I'm pretty sure my projects setup is correct (same run-time libs, etc.) Also, if I never actually use the vars, I can 'watch' them in the debugger and the values are correct.
Any suggestions about what I am doing wrong? I am using VS 2003 with IVF 8.1, running on w2k.
Thanks, Dave
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just tried a test case with IVF 9.1and it worked fine. I don't see anything wrong with what you wrote above - all I can think of is that you failed to get the Fortran .obj or .lib from the module's compilation linked in.
Do a "dumpbin -symbols" on the .obj output of the module compile. It may be that older compilers didn't "externalize" module variables that Fortran wouldn't need global symbols for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Steve,
Thank you very much for the reply. I think the module is getting linked in, but the problem (I think) may be that the c side is "decorating" the variable.
The linker error occurs in the c++ object file -- the output is pasted below (modTest is the cpp file, modLib is the fortran subproject, which includes (only) the module file EXAMP.f90). When I do a dumpbin on the 2 object files, the relevant lines are
(in modTest.obj)
01D 00000000 SECT5 notype External | ??_C@_0BA@GONBHIKL@?5EXAMP_mp_I1?5?$DN?5?$AA@ (`string')
01E 00000000 UNDEF notype External | _EXAMP_mp_I1
and in EXAMP.obj
01D 00000004 UNDEF notype External | EXAMP_mp_I1
Any ideas of what I can do to get around this? Thanks again,
Dave
output from the build:
------ Rebuild All started: Project: modLib, Configuration: Debug Win32 ------
Deleting intermediate files and output files for project 'modLib', configuration 'Debug|Win32'.
Compiling with Intel Fortran 8.1...
EXAMP.f90
D:Visual Studio ProjectsTest ProjectsmodTestmodLibEXAMP.f90(6) : Warning: The structure length is not a multiple of its largest element; could create misalignments for arrays of this type. [MYDATA]
Creating library...
Build log written to "file://D:Visual Studio ProjectsTest ProjectsmodTestmodLibDebugBuildLog.txt"
modLib build succeeded.
------ Rebuild All started: Project: modTest, Configuration: Debug Win32 ------
Deleting intermediate files and output files for project 'modTest', configuration 'Debug|Win32'.
Compiling...
stdafx.cpp
Compiling...
modTest.cpp
Linking...
modTest.obj : error LNK2001: unresolved external symbol _EXAMP_mp_I1
Debug/modTest.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://d:Visual Studio ProjectsTest ProjectsmodTestmodTestDebugBuildLog.htm"
modTest - 2 error(s), 0 warning(s)
---------------------- Done ----------------------
Rebuild All: 1 succeeded, 1 failed, 0 skipped
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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