- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am facing problems with mixed language project.
I have a fortran program created as static library project that is being called from c++,getting the errors as below,I tried a lot but was not able to resolve it hence thought of posting it here.
**************************
c1.cpp(39) : error C2065: '_fcom' : undeclared identifier
c1.cpp(39) : error C2228: left of '.a' must have class/struct/union type
type is ''unknown-type''
c1.cpp(46) : error C2228: left of '.b' must have class/struct/union type
type is ''unknown-type''
c1.cpp(46) : error C3861: '_fcom': identifier not found, even with argument-dependent lookup
c1.cpp(51) : error C2228: left of '.c1' must have class/struct/union type
type is ''unknown-type''
c1.cpp(51) : error C2228: left of '.c2' must have class/struct/union type
type is ''unknown-type''
c1.cpp(51) : error C3861: '_fcom': identifier not found, even with argument-dependent lookup
c1.cpp(51) : error C3861: '_fcom': identifier not found, even with argument-dependent lookup
**************************
I'll appreciate if someone can help me out with this.
I have a fortran program created as static library project that is being called from c++,getting the errors as below,I tried a lot but was not able to resolve it hence thought of posting it here.
**************************
c1.cpp(39) : error C2065: '_fcom' : undeclared identifier
c1.cpp(39) : error C2228: left of '.a' must have class/struct/union type
type is ''unknown-type''
c1.cpp(46) : error C2228: left of '.b' must have class/struct/union type
type is ''unknown-type''
c1.cpp(46) : error C3861: '_fcom': identifier not found, even with argument-dependent lookup
c1.cpp(51) : error C2228: left of '.c1' must have class/struct/union type
type is ''unknown-type''
c1.cpp(51) : error C2228: left of '.c2' must have class/struct/union type
type is ''unknown-type''
c1.cpp(51) : error C3861: '_fcom': identifier not found, even with argument-dependent lookup
c1.cpp(51) : error C3861: '_fcom': identifier not found, even with argument-dependent lookup
**************************
I'll appreciate if someone can help me out with this.
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You declared the fortran common without a preceeding underscore:
extern forcommon fcom; // To access the external /fcom/ fortran common...
but you use it with an underscore:
cout _fcom.a " ";
I don't know which method is correct (it depends on how the fortran compiler decorates symbols), but it has to be one or the other.
extern forcommon fcom; // To access the external /fcom/ fortran common...
but you use it with an underscore:
cout _fcom.a
I don't know which method is correct (it depends on how the fortran compiler decorates symbols), but it has to be one or the other.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Most Fortran compilers which are intended to work with C and C++ come with examples, which should get you started. Unless you use extensions such as ifort supports, to declare C++ interface in the Fortran source, your C++ must declare functions as extern "C":
extern "C" int fcom_();
so as to avoid C++ name mangling.
Your Fortran compiler probably has options to control link symbol case and underscore appending. Those may interfere with use of some of the libraries provided for your Fortran.
I guess you are using Windows, as your zip file isn't openable by my e-mail reader. With Microsoft compatible linking, you can use tools such as dumpbin /symbols, or equivalent link facilities, to see whether your symbols match.
Questions like this are more often answered in the Fortran forum, assuming you use a Fortran which is, or was, supported by Intel. I am guessing you may not be, as lower case symbols aren't a default with those compilers on Windows.
extern "C" int fcom_();
so as to avoid C++ name mangling.
Your Fortran compiler probably has options to control link symbol case and underscore appending. Those may interfere with use of some of the libraries provided for your Fortran.
I guess you are using Windows, as your zip file isn't openable by my e-mail reader. With Microsoft compatible linking, you can use tools such as dumpbin /symbols, or equivalent link facilities, to see whether your symbols match.
Questions like this are more often answered in the Fortran forum, assuming you use a Fortran which is, or was, supported by Intel. I am guessing you may not be, as lower case symbols aren't a default with those compilers on Windows.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I saw the f1.obj, and found that fcom was mapped into _fcom.
If you write "forcommon fcom;" in a CPP file, fcom may be mapped into ?fcom?xu???
if using extern "C", you can let Intel compiler map fcom into _fcom.
That is OK!
please try it:
#include
using namespace std;
// Def. a structure type to access external Fortran common area...
typedef struct { int a[6][5]; int b[2][2];
char c1[80]; char c2[80]; } forcommon;
// List of all modules not written in C/C++ language...
extern "C"{
double test( double& d);
void testmore( const char* e1, const int& se1, const char* e2, const int& se2);
}
extern "C" {
forcommon fcom;
} // To access the external /fcom/ fortran common...
int main()
{
double d1, d2;
char s1[]="just a test", s2[]="really a test";
int i, j;
d1 = 10.0;
d2 = test( d1 ); // test is an external Fortran function
int sizs1 = sizeof(s1);
int sizs2 = sizeof(s2);
testmore( s1, sizs1, s2, sizs2 ); // testmore is an external Fortran subroutine
cout d1 " " d2 endl;
for( i=0; i5; i++ ) {
for( j=0; j6; j++ ) {
cout fcom.a " ";
}
cout endl;
}
for( i=0; i2; i++ ) {
for( j=0; j2; j++ ) {
cout fcom.b " ";
}
cout endl;
}
cout _fcom.c1 " " _fcom.c2 endl;
return ( 0 );
}
If you write "forcommon fcom;" in a CPP file, fcom may be mapped into ?fcom?xu???
if using extern "C", you can let Intel compiler map fcom into _fcom.
That is OK!
please try it:
#include
using namespace std;
// Def. a structure type to access external Fortran common area...
typedef struct { int a[6][5]; int b[2][2];
char c1[80]; char c2[80]; } forcommon;
// List of all modules not written in C/C++ language...
extern "C"{
double test( double& d);
void testmore( const char* e1, const int& se1, const char* e2, const int& se2);
}
extern "C" {
forcommon fcom;
} // To access the external /fcom/ fortran common...
int main()
{
double d1, d2;
char s1[]="just a test", s2[]="really a test";
int i, j;
d1 = 10.0;
d2 = test( d1 ); // test is an external Fortran function
int sizs1 = sizeof(s1);
int sizs2 = sizeof(s2);
testmore( s1, sizs1, s2, sizs2 ); // testmore is an external Fortran subroutine
cout d1 " " d2 endl;
for( i=0; i5; i++ ) {
for( j=0; j6; j++ ) {
cout fcom.a
}
cout endl;
}
for( i=0; i2; i++ ) {
for( j=0; j2; j++ ) {
cout fcom.b
}
cout endl;
}
cout _fcom.c1 " " _fcom.c2 endl;
return ( 0 );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Some codes are deleted by auto-system?
note:_fcom in CPP file is problemable, you should make the following change:
_fcom.a --> fcom.a
_fcom.b --> fcom.b
_fcom.c1-->fcom.c1
_fcom.c2-->fcom.c2
note:_fcom in CPP file is problemable, you should make the following change:
_fcom.a
_fcom.b
_fcom.c1-->fcom.c1
_fcom.c2-->fcom.c2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The new c1.cpp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
c1.cpp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
or try it:
int main()
{
double d1, d2;
char s1[]="just a test", s2[]="really a test";
extern "C" forcommon fcom;
..............
}
int main()
{
double d1, d2;
char s1[]="just a test", s2[]="really a test";
extern "C" forcommon fcom;
..............
}

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