- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
extern "C"{
function a_
function b_ //These underscores are added assuming the fortran compiler will add them after the function
}
then naming convention__cdecl (/Gd) adds an underscore to the beggining of the c function like so
_a_
_b_
I cant figure out how to look at the object (.obj) or library (.lib) and analyze the contents, atleast the function names and how they have been mangled. Does anyone know what might be happening here or what the command is for looking at the functions in the obj files or lib file? Thanks.
W-
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can tell you how to fix this in C++ or in Fortran - which would you prefer?
- 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
Thanks. Can you tell me both? Which would be easier to implement? Thank you very much. I appreciate your help.
W-
- 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
SUBROUTINE A (arg, arg, arg)
to:
SUBROUTINE A (arg, arg, arg) BIND(C,NAME="a_")
where you specify the string for NAME= as the lowercase routine name followed by an underscore.
A way that is even simpler but may have side-effects and I do NOT recommend it, is to add the options:
/iface:cref /assume:underscore
to the Fortran compile options.
On the C++ side, you would need to change the names of the routines to be "A" instead of "a_", etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
W-
- 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
Hi Steve,
Thanks for the response. This is still not working. I noticed on here that it was refering to a couple of different .net versions as well as a couple of different intel VF versions. It only mentions intel version 10 or 11. Currently I am using version 9. Would this create a problem? Thanks.
W-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
W-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
While that worked I have encoutered another problem that I guess falls under the same topic so I wont start a new thread.
The functions are now linked but I have data that I need to use in both sets of code. For instance I have structures defined in .hpp in the c++/c code and an equivalentcommon block in the fortran code. For instance
.hpp file in c++/c code .h file in fortran code
struct abc{ common ABC, var 1, var 2
var 1
var 2
}
then in a cpp file I have
extern abc abc_
All fortran is uppercase and all c\c++ is lowercase. I tried to match case in case the same thing happens here that it does with the functions. That didnt work. In this case should we have more of the same that we have with the functions that I wasnt able to resolve yet or is there another issue with this case?
in the end the C/C++ will call the fortran functions but I have some initialization code that inits data into the c/c++ structures and I need to get from the c\c++ structures to the fortran code through the fortran common structureif that makes any sense. Thanks for any help!
By the way this is leading to an unresolved external struct abc abc_.
W-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Accessing Common Blocks and C Structures Directly
You can access Fortran common blocks directly from C by defining an external C structure with the appropriate fields, and making sure that alignment and padding between Fortran and C are compatible. The C and ALIAS ATTRIBUTES options can be used with a common block to allow mixed-case names.
As an example, suppose your Fortran code has a common block named
Really
, as shown:
!DEC$ ATTRIBUTES ALIAS:'Really' :: Really
REAL(4) x, y, z(6)
REAL(8) ydbl
COMMON / Really / x, y, z(6), ydbl
(my edit: The Fortran-forced upper-case name REALLY is aliased to 'Really' to match what the C-side uses)
You can access this data structure from your C code with the following external data structure:
#pragma pack(2)
extern struct {
float x, y, z[6];
double ydbl;
} Really;
#pragma pack()
You can also access C structures from Fortran by creating common blocks that correspond to those structures. This is the reverse case from that just described. However, the implementation is the same because after common blocks and structures have been defined and given a common address (name), and assuming the alignment in memory has been dealt with, both languages share the same memory locations for the variables.
P.S. I think that the above assumes that the Fortran and C-code are eventually linked together, or the Fortran is in a static library that is linked to/from. If the Fortran is in a DLL, you will need to add a DLLEXPORT directive for the common block name in teh Fortran and an import directive on the C side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
extern abc abc_ in an extern "C" and change the capitalization to what was described above. Thanks Steve.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
W-

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