- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello-
Please be gentle, i'm a fortran programmer with almost no C++ experience. I'm sure this is a very obvious question, but I'm trying to access a fortran module from a .cpp as described in the documentation. I'm unable to even reproduce the simple example without getting unresolved external errors.
i have a fortran static lib project called Lib1 that has a file called source1.f90 with the following:
MODULE EXAMP
REAL A(3)
INTEGER I1, I2
CHARACTER(80) LINE
TYPE MYDATA
SEQUENCE
INTEGER N
CHARACTER(30) INFO
END TYPE MYDATA
END MODULE EXAMP
I have a C++ console app project with a file called tryer.cpp with the following:
#include "stdafx.h"
// C code accessing module data in .cpp file
extern "C" float EXAMP_mp_A[3];
extern "C" int EXAMP_mp_I1, EXAMP_mp_I2;
extern "C" char EXAMP_mp_LINE[80];
extern "C" struct {
int N;
char INFO[30];
} EXAMP_mp_MYDATA;
int _tmain(int argc, _TCHAR* argv[])
{
float foo;
foo = EXAMP_mp_A[0];
return 0;
}
Both projects exist in a solution in VS. The fortran library is marked as a dependancy of the console app.
The compile log looks like this:
Creating temporary file "c:Documents and SettingsDavidMy DocumentsVisual Studio Projects ryerDebugRSP000067.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MLd /Yu"stdafx.h" /Fp"Debug/tryer.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /c /Wp64 /ZI /TP
". ryer.cpp"
]
Creating command line "cl.exe @"c:Documents and SettingsDavidMy DocumentsVisual Studio Projects ryerDebugRSP000067.rsp" /nologo"
Creating temporary file "c:Documents and SettingsDavidMy DocumentsVisual Studio Projects ryerDebugRSP000068.rsp" with contents
[
/OUT:"Debug/tryer.exe" /INCREMENTAL /NOLOGO /DEBUG /PDB:"Debug/tryer.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "Documents and SettingsDavidMy DocumentsVisual Studio ProjectsLib1debuglib1.lib"
".debugstdafx.obj"
".debug ryer.obj"
]
Creating command line "link.exe @"c:Documents and SettingsDavidMy DocumentsVisual Studio Projects ryerDebugRSP000068.rsp""
Please be gentle, i'm a fortran programmer with almost no C++ experience. I'm sure this is a very obvious question, but I'm trying to access a fortran module from a .cpp as described in the documentation. I'm unable to even reproduce the simple example without getting unresolved external errors.
i have a fortran static lib project called Lib1 that has a file called source1.f90 with the following:
MODULE EXAMP
REAL A(3)
INTEGER I1, I2
CHARACTER(80) LINE
TYPE MYDATA
SEQUENCE
INTEGER N
CHARACTER(30) INFO
END TYPE MYDATA
END MODULE EXAMP
I have a C++ console app project with a file called tryer.cpp with the following:
#include "stdafx.h"
// C code accessing module data in .cpp file
extern "C" float EXAMP_mp_A[3];
extern "C" int EXAMP_mp_I1, EXAMP_mp_I2;
extern "C" char EXAMP_mp_LINE[80];
extern "C" struct {
int N;
char INFO[30];
} EXAMP_mp_MYDATA;
int _tmain(int argc, _TCHAR* argv[])
{
float foo;
foo = EXAMP_mp_A[0];
return 0;
}
Both projects exist in a solution in VS. The fortran library is marked as a dependancy of the console app.
The compile log looks like this:
Creating temporary file "c:Documents and SettingsDavidMy DocumentsVisual Studio Projects ryerDebugRSP000067.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MLd /Yu"stdafx.h" /Fp"Debug/tryer.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /c /Wp64 /ZI /TP
". ryer.cpp"
]
Creating command line "cl.exe @"c:Documents and SettingsDavidMy DocumentsVisual Studio Projects ryerDebugRSP000067.rsp" /nologo"
Creating temporary file "c:Documents and SettingsDavidMy DocumentsVisual Studio Projects ryerDebugRSP000068.rsp" with contents
[
/OUT:"Debug/tryer.exe" /INCREMENTAL /NOLOGO /DEBUG /PDB:"Debug/tryer.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "Documents and SettingsDavidMy DocumentsVisual Studio ProjectsLib1debuglib1.lib"
".debugstdafx.obj"
".debug ryer.obj"
]
Creating command line "link.exe @"c:Documents and SettingsDavidMy DocumentsVisual Studio Projects ryerDebugRSP000068.rsp""
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okay, I admit I tried this from the command line, but I didn't get any unresolved externals.
What did you get? (If you said in your original post, I must have missed it ...)
If the undefines are the _EXAMP_mp_*, do a link /dump /symbols lib1.lib
and make sure they're there, and spelled correctly!
- Lorri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The error from the linking is this:
tryer.obj : error LNK2001: unresolved external symbol _EXAMP_mp_A
Debug/tryer.exe : fatal error LNK1120: 1 unresolved externals
the link /dump /symbols for Lib1.lib gives this:
01D 00000004 UNDEF notype External | EXAMP_mp_I2
01E 00000004 UNDEF notype External | EXAMP_mp_I1
01F 0000000C UNDEF notype External | EXAMP_mp_A
020 00000060 UNDEF notype External | EXAMP_mp_LINE
Is there an issue that they don't have the leading "_"?
tryer.obj : error LNK2001: unresolved external symbol _EXAMP_mp_A
Debug/tryer.exe : fatal error LNK1120: 1 unresolved externals
the link /dump /symbols for Lib1.lib gives this:
01D 00000004 UNDEF notype External | EXAMP_mp_I2
01E 00000004 UNDEF notype External | EXAMP_mp_I1
01F 0000000C UNDEF notype External | EXAMP_mp_A
020 00000060 UNDEF notype External | EXAMP_mp_LINE
Is there an issue that they don't have the leading "_"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I would say the issue was that the Fortran library names are created without the leading underscore.
Good. Now we just need to figure out how it got that way! What was the command used to compile the Fortran files? You can get that from the project options in .NET.
- Lorri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/nologo /Zi /Od /module:"$(INTDIR)/" /object:"$(INTDIR)/" /traceback /check:bounds /libs:static /dbglibs /libdir:noauto /c
i got this from propeties->fortran->command line in the window marked "all options".
i got this from propeties->fortran->command line in the window marked "all options".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What is the exact compiler version you are using? There have been bugs in this area in the past.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using the latest version i think?
Intel Fortran Compiler for 32-bit applications, Version 8.1 Build 20040802 Z Package ID: w_fc_p_8.1.019
I've been playing the command line and have had no success there as well. What command line options are used normally?
Also, if its of any interest, it appears that module procedures (subroutines and functions) have the leading underscore, while the variables do not.
So, if i add a function to the above module like so:
MODULE EXAMP
REAL A(3)
INTEGER I1, I2
CHARACTER(80) LINE
TYPE MYDATA
SEQUENCE
INTEGER N
CHARACTER(30) INFO
END TYPE MYDATA
CONTAINS
integer function foo ()
foo = 1
end function foo
END MODULE EXAMP
And compile with the following command: ifort -c source1.f90
then link /dump /symbols source1.obj gives me this:
00E 00000000 SECT1 notype () External | _EXAMP
00F 00000002 SECT1 notype () External | _EXAMP_mp_FOO
010 00000004 UNDEF notype External | EXAMP_mp_I2
011 00000004 UNDEF notype External | EXAMP_mp_I1
012 0000000C UNDEF notype External | EXAMP_mp_A
013 00000060 UNDEF notype External | EXAMP_mp_LINE
014 00000000 SECT7 notype Static | .drectve
I'd settle for using the command line but i'm apparently missing something. I'm used to developing in a unix environment, so i'm quite content with gVim as my IDE :)
Intel Fortran Compiler for 32-bit applications, Version 8.1 Build 20040802 Z Package ID: w_fc_p_8.1.019
I've been playing the command line and have had no success there as well. What command line options are used normally?
Also, if its of any interest, it appears that module procedures (subroutines and functions) have the leading underscore, while the variables do not.
So, if i add a function to the above module like so:
MODULE EXAMP
REAL A(3)
INTEGER I1, I2
CHARACTER(80) LINE
TYPE MYDATA
SEQUENCE
INTEGER N
CHARACTER(30) INFO
END TYPE MYDATA
CONTAINS
integer function foo ()
foo = 1
end function foo
END MODULE EXAMP
And compile with the following command: ifort -c source1.f90
then link /dump /symbols source1.obj gives me this:
00E 00000000 SECT1 notype () External | _EXAMP
00F 00000002 SECT1 notype () External | _EXAMP_mp_FOO
010 00000004 UNDEF notype External | EXAMP_mp_I2
011 00000004 UNDEF notype External | EXAMP_mp_I1
012 0000000C UNDEF notype External | EXAMP_mp_A
013 00000060 UNDEF notype External | EXAMP_mp_LINE
014 00000000 SECT7 notype Static | .drectve
I'd settle for using the command line but i'm apparently missing something. I'm used to developing in a unix environment, so i'm quite content with gVim as my IDE :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, that's an old version. 8.1.029 is the latest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So, i tried .029 and the naming is correct. However, i get a compiler error when trying to compile one of my fortran modules which did compile previously under .019. I tried .023 and everything seems to work fine under debug mode, but not under release (it fails on some of the gui libraries).
In any event this is particular issue is resolved. Thanks for your help.
In any event this is particular issue is resolved. Thanks for your help.

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